diff options
author | Nikita Popov <npopov@redhat.com> | 2024-05-22 07:40:08 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-05-31 08:55:59 +0200 |
commit | 63dc31b68b78bc0e5deef21b98cab72de997c471 (patch) | |
tree | 281d6ed5ad5c86de7584964ad1e74511036811d3 /llvm/lib/IR/ConstantFold.cpp | |
parent | 0821b7937c2b7528b1d3a0fa06eb241ae9ce4074 (diff) | |
download | llvm-63dc31b68b78bc0e5deef21b98cab72de997c471.zip llvm-63dc31b68b78bc0e5deef21b98cab72de997c471.tar.gz llvm-63dc31b68b78bc0e5deef21b98cab72de997c471.tar.bz2 |
Reapply [IR] Avoid creating icmp/fcmp constant expressions (#92885)
Reapply after https://github.com/llvm/llvm-project/pull/93548,
which should address the lldb failure on macos.
-----
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 9a7d437..0ef92ea 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; |