[llvm] 370e007 - [NFC] [IndVarSimplify] Add non-overflowing usub test (#159683)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 12:10:49 PDT 2025
Author: Florian Mayer
Date: 2025-09-21T12:10:45-07:00
New Revision: 370e00774048aa6e30819886735754724ee816e0
URL: https://github.com/llvm/llvm-project/commit/370e00774048aa6e30819886735754724ee816e0
DIFF: https://github.com/llvm/llvm-project/commit/370e00774048aa6e30819886735754724ee816e0.diff
LOG: [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.
Added:
Modified:
llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
index e678146c80af8..4a59e419369af 100644
--- a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
+++ b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
@@ -109,6 +109,37 @@ for.body: ; preds = %entry, %cont
%0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
%1 = extractvalue { i32, i1 } %0, 1
+; CHECK: for.body:
+; CHECK-NOT: @llvm.usub.with.overflow.i32
+; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
+ br i1 %1, label %trap, label %cont, !nosanitize !{}
+
+trap: ; preds = %for.body
+ tail call void @llvm.trap(), !nosanitize !{}
+ unreachable, !nosanitize !{}
+
+cont: ; preds = %for.body
+ %2 = extractvalue { i32, i1 } %0, 0
+ %cmp = icmp sgt i32 %2, 0
+ br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
+define void @f_usub_overflow(ptr nocapture %a) {
+; CHECK-LABEL: @f_usub_overflow(
+entry:
+ br label %for.body
+
+for.cond.cleanup: ; preds = %cont
+ ret void
+
+for.body: ; preds = %entry, %cont
+ %i.04 = phi i32 [ 15, %entry ], [ %2, %cont ]
+ %idxprom = sext i32 %i.04 to i64
+ %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom
+ store i8 0, ptr %arrayidx, align 1
+ %0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
+ %1 = extractvalue { i32, i1 } %0, 1
+
; It is theoretically possible to prove this, but SCEV cannot
; represent non-unsigned-wrapping subtraction operations.
More information about the llvm-commits
mailing list