diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-14 18:58:48 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:03:59 +0000 |
commit | 753f127f3ace09432b2baeffd71a308760641a62 (patch) | |
tree | 97694ab339c0ca6145ebb429c7505019565b9a60 /contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (diff) | |
parent | 1f917f69ff07f09b6dbb670971f57f8efe718b84 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp b/contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp index a81041845052..aa4da27be4e5 100644 --- a/contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp +++ b/contrib/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp @@ -30,6 +30,7 @@ #include "llvm/Analysis/VectorUtils.h" #include "llvm/Config/config.h" #include "llvm/IR/Constant.h" +#include "llvm/IR/ConstantFold.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" @@ -1142,8 +1143,12 @@ ConstantFoldConstantImpl(const Constant *C, const DataLayout &DL, Ops.push_back(NewC); } - if (auto *CE = dyn_cast<ConstantExpr>(C)) - return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI); + if (auto *CE = dyn_cast<ConstantExpr>(C)) { + if (Constant *Res = + ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI)) + return Res; + return const_cast<Constant *>(C); + } assert(isa<ConstantVector>(C)); return ConstantVector::get(Ops); @@ -1339,7 +1344,9 @@ Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, if (Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL)) return C; - return ConstantExpr::get(Opcode, LHS, RHS); + if (ConstantExpr::isDesirableBinOp(Opcode)) + return ConstantExpr::get(Opcode, LHS, RHS); + return ConstantFoldBinaryInstruction(Opcode, LHS, RHS); } Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *I, @@ -1390,6 +1397,8 @@ Constant *llvm::ConstantFoldFPInstOperands(unsigned Opcode, Constant *LHS, // Calculate constant result. Constant *C = ConstantFoldBinaryOpOperands(Opcode, Op0, Op1, DL); + if (!C) + return nullptr; // Flush denormal output if needed. return FlushFPConstant(C, I, /* IsOutput */ true); |