This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Given
---------------------------------------------------------------------- struct A a; const int B = 42;
void foo (int i) { if (i > 10) a.a = 42; else { a.b = 21; a.a = a.b + 21; }
if (a.a != B) link_error (); } ----------------------------------------------------------------------
GCC will not fold 'a.a != B' into '0'.
While CCP has all the logic to propagate the constants in this case, it is missing the ability to associate constants with stores and loads (i.e., pointer dereferences, structures and global/aliased variables). We don't keep loads and stores in SSA, but we do build a factored use-def web for them (in the virtual operands).
Essentially, the patch extends Brian Booth's work to propagate constants in global variables. It associates constant values with the SSA names in the V_MAY_DEF/V_MUST_DEF operands. However, this is not enough, because we glob partial loads/stores with the base symbol:
# a_5 = V_MAY_DEF <a_4> a.a = 2;
# VUSE <a_5> x_3 = a.b;
In the example above, CCP will associate value '2' with 'a_5', but it would be wrong to replace the load from 'a.b' with '2', because '2' had been stored into a.a. So, we also keep track of the memory reference expression where the store was done. This may not be necessary when we start representing partial loads and stores (Dan?).
Attachment:
20041014-store-ccp.diff.gz
Description: GNU Zip compressed data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |