[PATCH] D144842: [ConstraintElimination] Add upper bound info based on maximum type bounds for zext instructions

Zain Jaffal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 23:08:27 PST 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.

Utilize the new BoundInfo to optimize zext operations during decomposition by assigning an upperBound to zext based on the max value of the pre-zext width.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144842

Files:
  llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
  llvm/test/Transforms/ConstraintElimination/type-bounds.ll


Index: llvm/test/Transforms/ConstraintElimination/type-bounds.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/type-bounds.ll
+++ llvm/test/Transforms/ConstraintElimination/type-bounds.ll
@@ -14,7 +14,7 @@
 ; CHECK-NEXT:    br i1 [[CMP_1]], label [[COND:%.*]], label [[EXIT]]
 ; CHECK:       cond:
 ; CHECK-NEXT:    [[CMP_2:%.*]] = icmp ult i32 [[A_EXT]], [[B]]
-; CHECK-NEXT:    call void @use(i1 [[CMP_2]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    ret void
 ; CHECK:       exit:
 ; CHECK-NEXT:    ret void
@@ -161,7 +161,7 @@
 ; CHECK-NEXT:    br i1 [[CMP_1]], label [[COND:%.*]], label [[EXIT]]
 ; CHECK:       cond:
 ; CHECK-NEXT:    [[CMP_2:%.*]] = icmp ult i32 [[A_EXT]], [[B]]
-; CHECK-NEXT:    call void @use(i1 [[CMP_2]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    ret void
 ; CHECK:       exit:
 ; CHECK-NEXT:    ret void
@@ -239,8 +239,8 @@
 ; CHECK:       cond:
 ; CHECK-NEXT:    [[CMP_3:%.*]] = icmp ult i32 [[A_EXT]], [[B]]
 ; CHECK-NEXT:    [[CMP_4:%.*]] = icmp ult i32 [[A2_EXT]], [[B2]]
-; CHECK-NEXT:    call void @use(i1 [[CMP_3]])
-; CHECK-NEXT:    call void @use(i1 [[CMP_4]])
+; CHECK-NEXT:    call void @use(i1 true)
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    ret void
 ; CHECK:       exit:
 ; CHECK-NEXT:    ret void
Index: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -361,9 +361,16 @@
 
   Value *Op0;
   bool IsKnownNonNegative = false;
+  int64_t UpperBoundVal = MaxConstraintValue;
   if (match(V, m_ZExt(m_Value(Op0)))) {
     IsKnownNonNegative = true;
     V = Op0;
+    if (!llvm::any_of(V->users(),
+                      [&](User *User) { return isa<SExtInst>(User); })) {
+      TypeSize PreZextWidth =
+          DL.getTypeSizeInBits(V->getType()->getScalarType());
+      UpperBoundVal = APInt::getMaxValue(PreZextWidth).getZExtValue();
+    }
   }
 
   Value *Op1;
@@ -409,7 +416,7 @@
   if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1))))
     return {0, {{1, Op0}, {-1, Op1}}};
 
-  return {V, IsKnownNonNegative};
+  return {V, IsKnownNonNegative, UpperBoundVal};
 }
 
 ConstraintTy


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144842.500670.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/43ad7e58/attachment.bin>


More information about the llvm-commits mailing list