Skip to content

Commit a33edcb

Browse files
committed
fix PR7589: In brief:
gep P, (zext x) != gep P, (sext x) DecomposeGEPExpression was getting this wrong, confusing basicaa. llvm-svn: 111352
1 parent bc80329 commit a33edcb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,9 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
10181018
}
10191019
}
10201020

1021-
// Since clients don't care about the high bits of the value, just scales and
1022-
// offsets, we can look through extensions.
1023-
if (isa<SExtInst>(V) || isa<ZExtInst>(V)) {
1021+
// Since GEP indices are sign extended anyway, we don't care about the high
1022+
// bits of a sign extended value - just scales and offsets.
1023+
if (isa<SExtInst>(V)) {
10241024
Value *CastOp = cast<CastInst>(V)->getOperand(0);
10251025
unsigned OldWidth = Scale.getBitWidth();
10261026
unsigned SmallWidth = CastOp->getType()->getPrimitiveSizeInBits();

llvm/test/Analysis/BasicAA/featuretest.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,24 @@ define i32 @constexpr_test() {
104104
; CHECK: @constexpr_test
105105
; CHECK: ret i32 0
106106
}
107+
108+
109+
110+
; PR7589
111+
; These two index expressions are different, this cannot be CSE'd.
112+
define i16 @zext_sext_confusion(i16* %row2col, i5 %j) nounwind{
113+
entry:
114+
%sum5.cast = zext i5 %j to i64 ; <i64> [#uses=1]
115+
%P1 = getelementptr i16* %row2col, i64 %sum5.cast
116+
%row2col.load.1.2 = load i16* %P1, align 1 ; <i16> [#uses=1]
117+
118+
%sum13.cast31 = sext i5 %j to i6 ; <i6> [#uses=1]
119+
%sum13.cast = zext i6 %sum13.cast31 to i64 ; <i64> [#uses=1]
120+
%P2 = getelementptr i16* %row2col, i64 %sum13.cast
121+
%row2col.load.1.6 = load i16* %P2, align 1 ; <i16> [#uses=1]
122+
123+
%.ret = sub i16 %row2col.load.1.6, %row2col.load.1.2 ; <i16> [#uses=1]
124+
ret i16 %.ret
125+
; CHECK: @zext_sext_confusion
126+
; CHECK: ret i16 %.ret
127+
}

0 commit comments

Comments
 (0)