[PATCH] Look through addrspacecasts when turning ptr comparisons into index comparisons.

Philip Reames listmail at philipreames.com
Wed Feb 19 13:52:16 PST 2014


On 02/19/2014 10:41 AM, Matt Arsenault wrote:
> On Feb 19, 2014, at 10:01 AM, Philip Reames <listmail at philipreames.com> wrote:
>
>> Let me rephrase: I believe your patch would produce invalid IR if the other optimization case is hit.  We'd pick up your unwrapping of address space casts, but not the handling for mismatched widths.
>>
>> Specifically, I'm referring to this code:
>> if (TD &&
>>           GEPsInBounds &&
>>           (isa<ConstantExpr>(GEPLHS) || GEPLHS->hasOneUse()) &&
>>           (isa<ConstantExpr>(GEPRHS) || GEPRHS->hasOneUse())) {
>>         // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2)  ---> (OFFSET1 cmp OFFSET2)
>>         Value *L = EmitGEPOffset(GEPLHS);
>>        Value *R = EmitGEPOffset(GEPRHS);
>>         return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R); // <-- problem here
>> }
>>
>> Unless there's something I'm missing - feel free to point it out - your change would introduce regressions.
>>
>> Philip
>>
> I don’t think this part is reachable. This will only be reached if the base pointers of the GEPs are the same, in which case they have the same address space and therefore the same size.
>
I see your point.  This is quite subtle though.  Please add a comment or 
(preferably) an assert that the offset widths must be the same.

Philip



More information about the llvm-commits mailing list