Skip to content

Commit 370e007

Browse files
authored
[NFC] [IndVarSimplify] Add non-overflowing usub test (#159683)
We would reenter the loop with %i.04 being 0, so the usub would overflow to -1. This was the only test in this file that had an overflow in the loop, the other ones did not.
1 parent e764e19 commit 370e007

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ for.body: ; preds = %entry, %cont
109109
%0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
110110
%1 = extractvalue { i32, i1 } %0, 1
111111

112+
; CHECK: for.body:
113+
; CHECK-NOT: @llvm.usub.with.overflow.i32
114+
; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
115+
br i1 %1, label %trap, label %cont, !nosanitize !{}
116+
117+
trap: ; preds = %for.body
118+
tail call void @llvm.trap(), !nosanitize !{}
119+
unreachable, !nosanitize !{}
120+
121+
cont: ; preds = %for.body
122+
%2 = extractvalue { i32, i1 } %0, 0
123+
%cmp = icmp sgt i32 %2, 0
124+
br i1 %cmp, label %for.body, label %for.cond.cleanup
125+
}
126+
127+
define void @f_usub_overflow(ptr nocapture %a) {
128+
; CHECK-LABEL: @f_usub_overflow(
129+
entry:
130+
br label %for.body
131+
132+
for.cond.cleanup: ; preds = %cont
133+
ret void
134+
135+
for.body: ; preds = %entry, %cont
136+
%i.04 = phi i32 [ 15, %entry ], [ %2, %cont ]
137+
%idxprom = sext i32 %i.04 to i64
138+
%arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom
139+
store i8 0, ptr %arrayidx, align 1
140+
%0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
141+
%1 = extractvalue { i32, i1 } %0, 1
142+
112143
; It is theoretically possible to prove this, but SCEV cannot
113144
; represent non-unsigned-wrapping subtraction operations.
114145

0 commit comments

Comments
 (0)