[PATCH] D148326: [ConstraintElimination] Transfer info from sgt %a, %b to ugt %a, %b if %b > 0

Zain Jaffal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 04:12:25 PDT 2023


zjaffal created this revision.
zjaffal added reviewers: fhahn, nikic, spatel.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
zjaffal requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148326

Files:
  llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
  llvm/test/Transforms/ConstraintElimination/gep-sub.ll
  llvm/test/Transforms/ConstraintElimination/signed-query-unsigned-system.ll
  llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll


Index: llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll
+++ llvm/test/Transforms/ConstraintElimination/transfer-signed-facts-to-unsigned.ll
@@ -580,7 +580,7 @@
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
 ; CHECK-NEXT:    [[T_1:%.*]] = icmp ugt i8 [[IDX]], 2
 ; CHECK-NEXT:    [[T_2:%.*]] = icmp ugt i8 [[IDX]], 1
-; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 [[T_1]], [[T_2]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 true, true
 ; CHECK-NEXT:    [[C_1:%.*]] = icmp ugt i8 [[IDX]], 3
 ; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[C_1]]
 ; CHECK-NEXT:    ret i1 [[RES_2]]
@@ -602,7 +602,7 @@
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[A:%.*]], 2
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
 ; CHECK-NEXT:    [[T_1:%.*]] = icmp ugt i8 [[A]], 2
-; CHECK-NEXT:    ret i1 [[T_1]]
+; CHECK-NEXT:    ret i1 true
 ;
 entry:
   %cmp = icmp sgt i8 %a, 2
@@ -619,7 +619,7 @@
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP_2]])
 ; CHECK-NEXT:    [[T_1:%.*]] = icmp ugt i8 [[A]], [[B]]
-; CHECK-NEXT:    ret i1 [[T_1]]
+; CHECK-NEXT:    ret i1 true
 ;
 entry:
   %cmp = icmp sgt i8 %a, %b
Index: llvm/test/Transforms/ConstraintElimination/signed-query-unsigned-system.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/signed-query-unsigned-system.ll
+++ llvm/test/Transforms/ConstraintElimination/signed-query-unsigned-system.ll
@@ -39,7 +39,7 @@
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[A_SGT_0]])
 ; CHECK-NEXT:    [[EXT:%.*]] = zext i8 [[A]] to i16
 ; CHECK-NEXT:    [[T:%.*]] = icmp sgt i16 [[EXT]], 0
-; CHECK-NEXT:    ret i1 [[T]]
+; CHECK-NEXT:    ret i1 true
 ;
   %a.sgt.0 = icmp sgt i8 %a, 0
   call void @llvm.assume(i1 %a.sgt.0)
Index: llvm/test/Transforms/ConstraintElimination/gep-sub.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/gep-sub.ll
+++ llvm/test/Transforms/ConstraintElimination/gep-sub.ll
@@ -195,7 +195,7 @@
 ; CHECK-NEXT:    [[CMP_SUB_1:%.*]] = icmp ult ptr [[DST_SUB_1]], [[UPPER]]
 ; CHECK-NEXT:    [[DST_SUB_2:%.*]] = getelementptr inbounds i8, ptr [[DST_ADD_IDX]], i64 -2
 ; CHECK-NEXT:    [[CMP_SUB_2:%.*]] = icmp ult ptr [[DST_SUB_2]], [[UPPER]]
-; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 [[CMP_SUB_1]], [[CMP_SUB_2]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 true, true
 ; CHECK-NEXT:    [[DST_SUB_3:%.*]] = getelementptr inbounds i8, ptr [[DST_ADD_IDX]], i64 -3
 ; CHECK-NEXT:    [[CMP_SUB_3:%.*]] = icmp ult ptr [[DST_SUB_3]], [[UPPER]]
 ; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[CMP_SUB_3]]
Index: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -582,11 +582,15 @@
     if (doesHold(CmpInst::ICMP_SGE, A, ConstantInt::get(B->getType(), 0)))
       addFact(CmpInst::ICMP_ULT, A, B, NumIn, NumOut, DFSInStack);
     break;
-  case CmpInst::ICMP_SGT:
+  case CmpInst::ICMP_SGT: {
     if (doesHold(CmpInst::ICMP_SGE, B, ConstantInt::get(B->getType(), -1)))
       addFact(CmpInst::ICMP_UGE, A, ConstantInt::get(B->getType(), 0), NumIn,
               NumOut, DFSInStack);
+    if (doesHold(CmpInst::ICMP_SGE, B, ConstantInt::get(B->getType(), 0)))
+      addFact(CmpInst::ICMP_UGT, A, B, NumIn, NumOut, DFSInStack);
+
     break;
+  }
   case CmpInst::ICMP_SGE:
     if (doesHold(CmpInst::ICMP_SGE, B, ConstantInt::get(B->getType(), 0))) {
       addFact(CmpInst::ICMP_UGE, A, B, NumIn, NumOut, DFSInStack);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148326.513534.patch
Type: text/x-patch
Size: 3835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230414/a596b8a6/attachment.bin>


More information about the llvm-commits mailing list