- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
[NFC] [IndVarSimplify] add overflowing tests #159877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] [IndVarSimplify] add overflowing tests #159877
Conversation
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
| @llvm/pr-subscribers-llvm-transforms Author: Florian Mayer (fmayer) ChangesFull diff: https://github.com/llvm/llvm-project/pull/159877.diff 1 Files Affected: 
 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 [skip ci]
There was a problem hiding this 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
| 
 You mean use update test checks instead? | 
| 
 yep | 
| ; It is theoretically possible to prove this, but SCEV cannot | ||
| ; represent non-unsigned-wrapping subtraction operations. | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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").
| Ping | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Also use UTC for test instead.
Also use UTC for test instead.