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

Duncan Sands baldrick at free.fr
Thu Jan 13 15:22:20 PST 2011


Hi Chris,

>> The most common simplification missed by instsimplify in unoptimized bitcode
>> is "X != 0 ->  X" when X is a boolean.  This occurs a lot because of the way
>> llvm-gcc converts gcc's conditional expressions.  Add this, and a few other
>> similar transforms for completeness.
>
> Hi Duncan,
>
> I don't really understand the motivation here: unoptimized code has lots of missed stuff, and instsimplify doesn't run for it, no?

by unoptimized I mean just before the first instcombine run.  Since instcombine 
first sees if SimplifyInstruction can mulch each instruction before working on
it itself, catching missing simplifies on "unoptimized code" basically means
finding stuff that could have been moved from instcombine to SimplifyInstruction
but wasn't.  In the case in question I didn't remove stuff from instcombine but
it is still a win: if instcombine sees an ICmp with i1 operands it turns it into
a logical operation, for example

     case ICmpInst::ICMP_NE:                  // icmp eq i1 A, B -> A^B
       return BinaryOperator::CreateXor(Op0, Op1);

By catching cases in SimplifyInstruction you avoid creating a new instruction,
revisiting it etc.  This change reduced the number of instructions combined by
1% without any impact on final bitcode.

> In any case, this looks very familiar to code already in instcombine.  Can the instcombine code be zapped now?

Unfortunately not because the instcombine logic is too general, see above.

Ciao, Duncan.

PS: My program that automatically finds simplifications finds all kinds of
interesting ones [*] in optimized code, this unoptimized code one was just a
warm up you might say :)

[*] Interesting = occurs a lot.  The program first harvests IR sequences from
the test-suite, and orders them by how often they occur, before looking for
simplifications in them.



More information about the llvm-commits mailing list