diff options
author | Cameron McInally <cameron.mcinally@nyu.edu> | 2019-05-05 16:07:09 +0000 |
---|---|---|
committer | Cameron McInally <cameron.mcinally@nyu.edu> | 2019-05-05 16:07:09 +0000 |
commit | 1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2 (patch) | |
tree | bc2a42daa117355c7d3a43a82ce69c34ea357883 /llvm/lib/IR/Constants.cpp | |
parent | 70ee2def906e928624f59611c3de732fe121b8a4 (diff) | |
download | llvm-1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2.zip llvm-1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2.tar.gz llvm-1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2.tar.bz2 |
Add FNeg IR constant folding support
llvm-svn: 359982
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 00c7226..5545eb4 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1830,7 +1830,8 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C, unsigned Flags, } #endif - // TODO: Try to constant fold operation. + if (Constant *FC = ConstantFoldUnaryInstruction(Opcode, C)) + return FC; if (OnlyIfReducedTy == C->getType()) return nullptr; @@ -1909,7 +1910,7 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2, #endif if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2)) - return FC; // Fold a few common cases. + return FC; if (OnlyIfReducedTy == C1->getType()) return nullptr; @@ -2235,7 +2236,7 @@ Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) { Constant *ConstantExpr::getFNeg(Constant *C) { assert(C->getType()->isFPOrFPVectorTy() && "Cannot FNEG a non-floating-point value!"); - return getFSub(ConstantFP::getZeroValueForNegation(C->getType()), C); + return get(Instruction::FNeg, C); } Constant *ConstantExpr::getNot(Constant *C) { @@ -3024,7 +3025,8 @@ Instruction *ConstantExpr::getAsInstruction() { case Instruction::FCmp: return CmpInst::Create((Instruction::OtherOps)getOpcode(), (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1]); - + case Instruction::FNeg: + return UnaryOperator::Create((Instruction::UnaryOps)getOpcode(), Ops[0]); default: assert(getNumOperands() == 2 && "Must be binary operator?"); BinaryOperator *BO = |