[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
Thu Mar 30 03:07:44 PDT 2023
zjaffal updated this revision to Diff 509590.
zjaffal added a comment.
Add condition to prevent generating upperbounds for variables with bitwidth > 64
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144842/new/
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
@@ -242,7 +242,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
@@ -349,8 +349,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,17 @@
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());
+ if (PreZextWidth <= 64)
+ UpperBoundVal = APInt::getMaxValue(PreZextWidth).getZExtValue();
+ }
}
Value *Op1;
@@ -416,7 +424,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.509590.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230330/b976eea8/attachment.bin>
More information about the llvm-commits
mailing list