Skip to content

Conversation

@fmayer
Copy link
Contributor

@fmayer fmayer commented Sep 19, 2025

Also use UTC for test instead.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Florian Mayer (fmayer)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/159877.diff

1 Files Affected:

  • (modified) llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll (+95)
diff --git a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
index 4a59e419369af..b5f8f9ece6809 100644
--- a/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
+++ b/llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
@@ -33,6 +33,35 @@ cont:                                             ; preds = %for.body
   br i1 %cmp, label %for.body, label %for.cond.cleanup
 }
 
+define void @f_sadd_overflow(ptr %a) {
+; CHECK-LABEL: @f_sadd_overflow(
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %cont
+  ret void
+
+for.body:                                         ; preds = %entry, %cont
+  %i.04 = phi i32 [ 2147483645, %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.sadd.with.overflow.i32(i32 %i.04, i32 1)
+  %1 = extractvalue { i32, i1 } %0, 1
+; CHECK: cont:
+; CHECK: br i1 true, label %for.body, label %for.cond.cleanup
+  br i1 %1, label %trap, label %cont, !nosanitize !{}
+
+trap:                                             ; preds = %for.body
+  tail call void @llvm.trap() #2, !nosanitize !{}
+  unreachable, !nosanitize !{}
+
+cont:                                             ; preds = %for.body
+  %2 = extractvalue { i32, i1 } %0, 0
+  %cmp = icmp sle i32 %2, 2147483647
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
 define void @f_uadd(ptr %a) {
 ; CHECK-LABEL: @f_uadd(
 entry:
@@ -63,6 +92,36 @@ cont:                                             ; preds = %for.body
   br i1 %cmp, label %for.body, label %for.cond.cleanup
 }
 
+define void @f_uadd_overflow(ptr %a) {
+; CHECK-LABEL: @f_uadd_overflow(
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %cont
+  ret void
+
+for.body:                                         ; preds = %entry, %cont
+  %i.04 = phi i32 [ 4294967290, %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.uadd.with.overflow.i32(i32 %i.04, i32 1)
+  %1 = extractvalue { i32, i1 } %0, 1
+; CHECK: cont:
+; CHECK: br i1 true, label %for.body, label %for.cond.cleanup
+  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 ule i32 %2, 4294967295
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
+
 define void @f_ssub(ptr nocapture %a) {
 ; CHECK-LABEL: @f_ssub(
 entry:
@@ -78,6 +137,9 @@ for.body:                                         ; preds = %entry, %cont
   store i8 0, ptr %arrayidx, align 1
   %0 = tail call { i32, i1 } @llvm.ssub.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-NOT: @llvm.ssub.with.overflow.i32
 ; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
@@ -93,6 +155,37 @@ cont:                                             ; preds = %for.body
   br i1 %cmp, label %for.body, label %for.cond.cleanup
 }
 
+define void @f_ssub_overflow(ptr nocapture %a) {
+; CHECK-LABEL: @f_ssub_overflow(
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %cont
+  ret void
+
+for.body:                                         ; preds = %entry, %cont
+  %i.04 = phi i32 [ -2147483642, %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.ssub.with.overflow.i32(i32 %i.04, i32 1)
+  %1 = extractvalue { i32, i1 } %0, 1
+; CHECK:  [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1
+; CHECK-NEXT:  br i1 [[COND]], label %trap, label %cont, !nosanitize !0
+; CHECK: cont:
+; CHECK: br i1 true, label %for.body, label %for.cond.cleanup
+  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 sge i32 %2, -2147483648
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
 define void @f_usub(ptr nocapture %a) {
 ; CHECK-LABEL: @f_usub(
 entry:
@@ -146,6 +239,8 @@ for.body:                                         ; preds = %entry, %cont
 ; CHECK: for.body:
 ; CHECK:  [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1
 ; CHECK-NEXT:  br i1 [[COND]], label %trap, label %cont, !nosanitize !0
+; CHECK: cont:
+; CHECK: br i1 true, label %for.body, label %for.cond.cleanup
   br i1 %1, label %trap, label %cont, !nosanitize !{}
 
 trap:                                             ; preds = %for.body

Created using spr 1.3.4
Created using spr 1.3.4
@fmayer fmayer requested a review from fhahn September 19, 2025 23:41
ndrewh and others added 2 commits September 22, 2025 13:02
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@fmayer fmayer changed the base branch from users/fmayer/spr/main.nfc-indvarsimplify-add-overflowing-tests to main September 22, 2025 20:03
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I think the isolated check lines make it a bit hard to see what is actually going on. Not sure what others think, bout it might be clearer with generating full check lines

@fmayer
Copy link
Contributor Author

fmayer commented Sep 22, 2025

FWIW I think the isolated check lines make it a bit hard to see what is actually going on. Not sure what others think, bout it might be clearer with generating full check lines

You mean use update test checks instead?

@fhahn
Copy link
Contributor

fhahn commented Sep 23, 2025

FWIW I think the isolated check lines make it a bit hard to see what is actually going on. Not sure what others think, bout it might be clearer with generating full check lines

You mean use update test checks instead?

yep

@fmayer fmayer requested a review from fhahn September 23, 2025 19:12
Created using spr 1.3.4
Comment on lines 361 to 362
; It is theoretically possible to prove this, but SCEV cannot
; represent non-unsigned-wrapping subtraction operations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move the comment to the top of the function and check if there are others that also need to be moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to what I understood the comment to mean (because it refers to a quite ambiguous "this").

Created using spr 1.3.4
@fmayer fmayer requested a review from fhahn September 24, 2025 19:10
@fmayer
Copy link
Contributor Author

fmayer commented Sep 30, 2025

Ping

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@fmayer fmayer merged commit 1c11f72 into main Sep 30, 2025
9 checks passed
@fmayer fmayer deleted the users/fmayer/spr/nfc-indvarsimplify-add-overflowing-tests branch September 30, 2025 22:19
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants