You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If all indices are the same, just compare the base pointers.
if (IndicesTheSame)
return new ICmpInst(ICmpInst::getSignedPredicate(Cond),
GEPLHS->getOperand(0), GEPRHS->getOperand(0));
We always use the signed version of the condition for some reason.
A consequence of this is that the following two functions aren't the same!
struct blah {
char thing[1];
};
bool f(struct blah *a, struct blah *b) {
char *c = a->thing;
char *d = b->thing;
return c < d;
}
Extended Description
If I give instcombine the following IR:
define i1 @f([1 x i8]* %a, [1 x i8]* %b) {
%c = getelementptr [1 x i8]* %a, i32 0, i32 0
%d = getelementptr [1 x i8]* %b, i32 0, i32 0
%cmp = icmp ult i8* %c, %d
ret i1 %cmp
}
opt -instcombine turns it into:
define i1 @f([1 x i8]* %a, [1 x i8]* %b) {
%cmp = icmp slt [1 x i8]* %a, %b
ret i1 %cmp
}
i.e it has turned an unsigned pointer comparision into a signed comparision that will give different results with some inputs.
The text was updated successfully, but these errors were encountered: