[llvm-commits] patch: folding (zext (and x, cst))

Nick Lewycky nicholas at mxc.ca
Tue Jun 7 23:11:05 PDT 2011


Jakob Stoklund Olesen wrote:
>
> On Jun 7, 2011, at 7:58 AM, Eli Friedman wrote:
>
>> On Tue, Jun 7, 2011 at 2:46 AM, Nick Lewycky<nicholas at mxc.ca>  wrote:
>>> I have an unfinished patch. I was looking to optimize:
>>>
>>>   define i32 @test1(i8 %x) nounwind readnone {
>>>     %A = and i8 %x, -32
>>>     %B = zext i8 %A to i32
>>>     ret i32 %B
>>>   }
>>>
>>> which currently does a mov into %al, then the "and", then extends, into
>>> doing a single extending mov, then an "and" in 32-bits. The rule I decided
>>> upon is "(zext (and x, cst)) ->  (and (anyext x), (zext cst))" in the DAG
>>> combiner.
>>
>> Just a comment, without reading the patch: it would be much more
>> conservative to fold (zext (and (load x), cst)) ->  (and (zextload x),
>> (zext cst)).  The transform you're proposing is much less obviously
>> beneficial.
>
> Also make sure this does the right thing on x86 when the zext is i32 ->  i64. The and implicitly zero-extends to 64 bit.

Could you elaborate? Are you saying that ISD::AND may have a wider 
result than its arguments?

Nick



More information about the llvm-commits mailing list