[PATCH] D137847: [ConstraintElimination] Make decompose() infallible
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 11 08:04:15 PST 2022
nikic created this revision.
nikic added a reviewer: fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
decompose() currently returns a mix of `{}` and `0 + 1*V` on failure. I don't really follow why we use one over the other in some cases. It seems like it would be better to make decompose() infallible and always return `0 + 1*V` is we can't decompose the value further.
https://reviews.llvm.org/D137847
Files:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
Index: llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
===================================================================
--- llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
+++ llvm/test/Transforms/ConstraintElimination/large-constant-ints.ll
@@ -105,7 +105,7 @@
; CHECK: then:
; CHECK-NEXT: [[SUB_1:%.*]] = sub nuw i80 [[A]], 1973801615886922022913
; CHECK-NEXT: [[C_1:%.*]] = icmp ult i80 [[SUB_1]], 1346612317380797267967
-; CHECK-NEXT: ret i1 [[C_1]]
+; CHECK-NEXT: ret i1 true
; CHECK: else:
; CHECK-NEXT: ret i1 false
;
Index: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -210,7 +210,7 @@
// Do not reason about pointers where the index size is larger than 64 bits,
// as the coefficients used to encode constraints are 64 bit integers.
if (DL.getIndexTypeSizeInBits(GEP.getPointerOperand()->getType()) > 64)
- return {};
+ return {{0, nullptr}, {1, &GEP}};
if (!GEP.isInBounds())
return {{0, nullptr}, {1, &GEP}};
@@ -226,7 +226,7 @@
auto GTI = gep_type_begin(GEP);
// Bail out for scalable vectors for now.
if (isa<ScalableVectorType>(GTI.getIndexedType()))
- return {};
+ return {{0, nullptr}, {1, &GEP}};
int64_t Scale = static_cast<int64_t>(
DL.getTypeAllocSize(GTI.getIndexedType()).getFixedSize());
@@ -253,7 +253,7 @@
// Bail out for scalable vectors for now.
if (isa<ScalableVectorType>(GTI.getIndexedType()))
- return {};
+ return {{0, nullptr}, {1, &GEP}};
// Struct indices must be constants (and reference an existing field). Add
// them to the constant factor.
@@ -304,8 +304,6 @@
bool IsSignedB) -> SmallVector<DecompEntry, 4> {
auto ResA = decompose(A, Preconditions, IsSigned, DL);
auto ResB = decompose(B, Preconditions, IsSignedB, DL);
- if (ResA.empty() || ResB.empty())
- return {};
ResA[0].Coefficient += ResB[0].Coefficient;
append_range(ResA, drop_begin(ResB));
return ResA;
@@ -327,7 +325,7 @@
if (auto *CI = dyn_cast<ConstantInt>(V)) {
if (CI->uge(MaxConstraintValue))
- return {};
+ return {{0, nullptr}, {1, V}};
return {{int64_t(CI->getZExtValue()), nullptr}};
}
@@ -434,10 +432,6 @@
Preconditions, IsSigned, DL);
auto BDec = decompose(Op1->stripPointerCastsSameRepresentation(),
Preconditions, IsSigned, DL);
- // Skip if decomposing either of the values failed.
- if (ADec.empty() || BDec.empty())
- return {};
-
int64_t Offset1 = ADec[0].Coefficient;
int64_t Offset2 = BDec[0].Coefficient;
Offset1 *= -1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137847.474774.patch
Type: text/x-patch
Size: 2866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221111/4fe89954/attachment.bin>
More information about the llvm-commits
mailing list