[llvm-commits] [llvm] r123754 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/2010-12-20-Distribute.ll

Duncan Sands baldrick at free.fr
Tue Jan 18 23:36:20 PST 2011


Hi Chris,

>> Simplify (X<<1)-X into X.  According to my auto-simplier this is the most common missed
>> simplification in fully optimized code.  It occurs sporadically in the testsuite, and
>> many times in 403.gcc: the final bitcode has 131 fewer subtractions after this change.
>> The reason that the multiplies are not eliminated is the same reason that instcombine
>> did not catch this: they are used by other instructions (instcombine catches this with
>> a more general transform which in general is only profitable if the operands have only
>> one use).
>
> Cool.  Please add a comment to the code about why the explicit multiply is checked.  I still don't understand what the multiply having multiple uses has to do with it.  It seems that you can completely drop "match(Op0, m_Mul(m_Specific(Op1), m_ConstantInt<2>())) ||" since it should always be canonicalized to a shift.

the explicit multiply is because when compiling at -O2 this code is called by
Early-CSE before multiplies have been canonicalized (the first Early-CSE pass
occurs before instcombine has run).

As for what multiple uses has to do with anything: instcombine performs the more
general transform "X*C-X -> X*(C-1)" but it only does it if "X*C" has one use
since otherwise you'd end up with two multiplications rather than one.  (Note
that instcombine handles "X*2" and "X<<1" the same way; I will write X*2).  What
instcombine didn't notice is that if C equals 2 then you don't get an extra mul
since "X*(C-1)" simplifies to "X".  Anyway, as a result if in optimized bitcode
you see a "X*2 - X" then you can be sure that "X*2" has more than one use since
otherwise instcombine would have zapped it, so simplifying "X*2 - X" to "X" is
only going to eliminate the subtraction and not the multiplication "X*2", which
is exactly what you see in 403.gcc for example: lots of subtractions removed,
but no multiplications removed.

Ciao, Duncan.



More information about the llvm-commits mailing list