[LLVMdev] Instruction combiner: converting arithmetic into bit operations

Krzysztof Parzyszek kparzysz at codeaurora.org
Wed Oct 17 08:31:15 PDT 2012


Hi,
I've noticed that for a while, the instruction combiner would convert 
certain arithmetic operations (like + or *) into bit-manipulation 
operations.  Specific example I have in mind is converting "2*x+1" into 
"(x<<1)|1".  What is the intention of doing this?

The reason I ask is that this kind of transformation makes it harder for 
later code to analyze it.  In general, it's a lot easier to reason about 
arithmetic operations, when they are not interleaved with bit 
operations.  For example, if we subtract 1 in the example above, the 
expression (A+1)-1 can be simplified to A without having to know that A 
is 2*x.  This is not possible to do in case of (B|1)-1 without knowing 
that B has the lowest bit 0.

In my opinion it would be better to leave arithmetic expressions as they 
are in the bitcode, and leave conversions like the one from 2^N*x to 
x<<N to the backends.

Any comments?

-Krzysztof

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation



More information about the llvm-dev mailing list