[llvm] 75af628 - [ConstraintElim] Add tests for gep nuw (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 04:17:11 PST 2024


Author: Nikita Popov
Date: 2024-12-04T13:17:02+01:00
New Revision: 75af62839b60a10439e8a31362d234b02c3958ba

URL: https://github.com/llvm/llvm-project/commit/75af62839b60a10439e8a31362d234b02c3958ba
DIFF: https://github.com/llvm/llvm-project/commit/75af62839b60a10439e8a31362d234b02c3958ba.diff

LOG: [ConstraintElim] Add tests for gep nuw (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/ConstraintElimination/gep-arithmetic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ConstraintElimination/gep-arithmetic.ll b/llvm/test/Transforms/ConstraintElimination/gep-arithmetic.ll
index 5e2bab28807f54..98bf01ef376317 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-arithmetic.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-arithmetic.ll
@@ -695,3 +695,75 @@ define i1 @test_missing_nusw(ptr %p, i32 %x, i32 %y) {
   %cmp2 = icmp ugt ptr %gep.x1, %gep.y
   ret i1 %cmp2
 }
+
+define i1 @test_nuw(ptr %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test_nuw(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
+; CHECK-NEXT:    [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
+; CHECK-NEXT:    [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ugt ptr [[GEP_X]], [[GEP_Y]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp ugt i64 %x, %y
+  call void @llvm.assume(i1 %cmp1)
+  %gep.x = getelementptr nuw i8, ptr %p, i64 %x
+  %gep.y = getelementptr nuw i8, ptr %p, i64 %y
+  %cmp2 = icmp ugt ptr %gep.x, %gep.y
+  ret i1 %cmp2
+}
+
+define i1 @test_nuw_nested(ptr %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test_nuw_nested(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
+; CHECK-NEXT:    [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
+; CHECK-NEXT:    [[GEP_X1:%.*]] = getelementptr nuw i8, ptr [[GEP_X]], i64 1
+; CHECK-NEXT:    [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ugt ptr [[GEP_X1]], [[GEP_Y]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp ugt i64 %x, %y
+  call void @llvm.assume(i1 %cmp1)
+  %gep.x = getelementptr nuw i8, ptr %p, i64 %x
+  %gep.x1 = getelementptr nuw i8, ptr %gep.x, i64 1
+  %gep.y = getelementptr nuw i8, ptr %p, i64 %y
+  %cmp2 = icmp ugt ptr %gep.x1, %gep.y
+  ret i1 %cmp2
+}
+
+define i1 @test_nuw_nested_missing_nuw(ptr %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test_nuw_nested_missing_nuw(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
+; CHECK-NEXT:    [[GEP_X:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[X]]
+; CHECK-NEXT:    [[GEP_X1:%.*]] = getelementptr nuw i8, ptr [[GEP_X]], i64 1
+; CHECK-NEXT:    [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ugt ptr [[GEP_X1]], [[GEP_Y]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp ugt i64 %x, %y
+  call void @llvm.assume(i1 %cmp1)
+  %gep.x = getelementptr i8, ptr %p, i64 %x
+  %gep.x1 = getelementptr nuw i8, ptr %gep.x, i64 1
+  %gep.y = getelementptr nuw i8, ptr %p, i64 %y
+  %cmp2 = icmp ugt ptr %gep.x1, %gep.y
+  ret i1 %cmp2
+}
+
+define i1 @test_nuw_incorrect_precondition(ptr %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test_nuw_incorrect_precondition(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp uge i64 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
+; CHECK-NEXT:    [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
+; CHECK-NEXT:    [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ugt ptr [[GEP_X]], [[GEP_Y]]
+; CHECK-NEXT:    ret i1 [[CMP2]]
+;
+  %cmp1 = icmp uge i64 %x, %y
+  call void @llvm.assume(i1 %cmp1)
+  %gep.x = getelementptr nuw i8, ptr %p, i64 %x
+  %gep.y = getelementptr nuw i8, ptr %p, i64 %y
+  %cmp2 = icmp ugt ptr %gep.x, %gep.y
+  ret i1 %cmp2
+}


        


More information about the llvm-commits mailing list