[llvm-commits] [llvm] r120028 - in /llvm/trunk: lib/Target/README.txt lib/Transforms/InstCombine/InstCombineShifts.cpp test/Transforms/InstCombine/shift.ll

Benjamin Kramer benny.kra at googlemail.com
Tue Nov 23 12:05:31 PST 2010


On 23.11.2010, at 20:20, Chris Lattner wrote:

> 
> On Nov 23, 2010, at 10:52 AM, Benjamin Kramer wrote:
> 
>> Author: d0k
>> Date: Tue Nov 23 12:52:42 2010
>> New Revision: 120028
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=120028&view=rev
>> Log:
>> InstCombine: Reduce "X shift (A srem B)" to "X shift (A urem B)" iff B is positive.
>> 
>> This allows to transform the rem in "1 << ((int)x % 8);" to an and.
> 
> Nifty.  Could this be generalized into SimplifyDemandedBits?  It seems that the srem simplifies because the shift doesn't need all the result bits of it.

I'm not sure that's safe, this optimization relies on the fact that any shift by an amount <= 0 is undefined,
I don't think SimplifyDemandedBits can model that. While "(negative value) srem (positive value)" always returns
a negative number or zero, "(negative value) urem (positive value)" will just return nonsense rather than a
truncated value.



More information about the llvm-commits mailing list