diff options
author | Nikita Popov <npopov@redhat.com> | 2024-05-22 07:40:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-22 07:40:08 +0200 |
commit | 108575f02ea9927009ed81231474d3a6f053602f (patch) | |
tree | a6f7cff34d60be83dbac1bd8623be418943c1d40 /llvm/lib/IR/ConstantFold.cpp | |
parent | 7370b109b44a187e55d032d9628e41a7b94c3914 (diff) | |
download | llvm-108575f02ea9927009ed81231474d3a6f053602f.zip llvm-108575f02ea9927009ed81231474d3a6f053602f.tar.gz llvm-108575f02ea9927009ed81231474d3a6f053602f.tar.bz2 |
[IR] Avoid creating icmp/fcmp constant expressions (#92885)
Do not create icmp/fcmp constant expressions in IRBuilder etc anymore,
i.e. treat them as "undesirable". This is in preparation for removing
them entirely.
Part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 4622ad7..2c99f39 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1282,9 +1282,9 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, // Fast path for splatted constants. if (Constant *C1Splat = C1->getSplatValue()) if (Constant *C2Splat = C2->getSplatValue()) - return ConstantVector::getSplat( - C1VTy->getElementCount(), - ConstantExpr::getCompare(Predicate, C1Splat, C2Splat)); + if (Constant *Elt = + ConstantFoldCompareInstruction(Predicate, C1Splat, C2Splat)) + return ConstantVector::getSplat(C1VTy->getElementCount(), Elt); // Do not iterate on scalable vector. The number of elements is unknown at // compile-time. @@ -1302,8 +1302,11 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, ConstantExpr::getExtractElement(C1, ConstantInt::get(Ty, I)); Constant *C2E = ConstantExpr::getExtractElement(C2, ConstantInt::get(Ty, I)); + Constant *Elt = ConstantFoldCompareInstruction(Predicate, C1E, C2E); + if (!Elt) + return nullptr; - ResElts.push_back(ConstantExpr::getCompare(Predicate, C1E, C2E)); + ResElts.push_back(Elt); } return ConstantVector::get(ResElts); @@ -1411,7 +1414,7 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, // other way if possible. // Also, if C1 is null and C2 isn't, flip them around. Predicate = ICmpInst::getSwappedPredicate(Predicate); - return ConstantExpr::getICmp(Predicate, C2, C1); + return ConstantFoldCompareInstruction(Predicate, C2, C1); } } return nullptr; |