From bbcb10ada14b926b6bbd063025f450c676d0072b Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 18 Sep 2025 18:10:57 -0700 Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- .../Transforms/IndVarSimplify/X86/overflow-intrinsics.ll | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll index e678146c80af8..c7db8b962f3d6 100644 --- a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll +++ b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll @@ -109,12 +109,9 @@ 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 -; It is theoretically possible to prove this, but SCEV cannot -; represent non-unsigned-wrapping subtraction operations. - ; CHECK: for.body: -; CHECK: [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1 -; CHECK-NEXT: br i1 [[COND]], label %trap, label %cont, !nosanitize !0 +; 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 @@ -123,7 +120,7 @@ trap: ; preds = %for.body cont: ; preds = %for.body %2 = extractvalue { i32, i1 } %0, 0 - %cmp = icmp sgt i32 %2, -1 + %cmp = icmp sgt i32 %2, 0 br i1 %cmp, label %for.body, label %for.cond.cleanup } From f77fa7fcfe63111ed41af865f474b0cea20e58f5 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 19 Sep 2025 16:09:17 -0700 Subject: [PATCH 2/3] address Created using spr 1.3.4 --- .../IndVarSimplify/X86/overflow-intrinsics.ll | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll index c7db8b962f3d6..0903d5cbda6a4 100644 --- a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll +++ b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll @@ -124,6 +124,37 @@ cont: ; preds = %for.body 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 + +; CHECK: for.body: +; CHECK: [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1 +; CHECK-NEXT: br i1 [[COND]], 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, -1 + br i1 %cmp, label %for.body, label %for.cond.cleanup +} + declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone From bc6bf5ee39a33b437bb1a9a727b9e81a346436ea Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 19 Sep 2025 16:37:44 -0700 Subject: [PATCH 3/3] fixup Created using spr 1.3.4 --- llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll index 0903d5cbda6a4..4a59e419369af 100644 --- a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll +++ b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll @@ -140,6 +140,9 @@ 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 +; It is theoretically possible to prove this, but SCEV cannot +; represent non-unsigned-wrapping subtraction operations. + ; CHECK: for.body: ; CHECK: [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1 ; CHECK-NEXT: br i1 [[COND]], label %trap, label %cont, !nosanitize !0