summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorCameron McInally <cameron.mcinally@nyu.edu>2019-05-05 16:07:09 +0000
committerCameron McInally <cameron.mcinally@nyu.edu>2019-05-05 16:07:09 +0000
commit1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2 (patch)
treebc2a42daa117355c7d3a43a82ce69c34ea357883 /llvm/lib/Analysis/ConstantFolding.cpp
parent70ee2def906e928624f59611c3de732fe121b8a4 (diff)
downloadbcm5719-llvm-1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2.tar.gz
bcm5719-llvm-1d0c845d9dce577c2ef14cd7d5fcf0b9c17f9ed2.zip
Add FNeg IR constant folding support
llvm-svn: 359982
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 74468e8dd72..2ea1e7dea82 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -999,7 +999,9 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
const TargetLibraryInfo *TLI) {
Type *DestTy = InstOrCE->getType();
- // Handle easy binops first.
+ if (Instruction::isUnaryOp(Opcode))
+ return ConstantFoldUnaryOpOperand(Opcode, Ops[0], DL);
+
if (Instruction::isBinaryOp(Opcode))
return ConstantFoldBinaryOpOperands(Opcode, Ops[0], Ops[1], DL);
@@ -1262,6 +1264,13 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
return ConstantExpr::getCompare(Predicate, Ops0, Ops1);
}
+Constant *llvm::ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op,
+ const DataLayout &DL) {
+ assert(Instruction::isUnaryOp(Opcode));
+
+ return ConstantExpr::get(Opcode, Op);
+}
+
Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,
Constant *RHS,
const DataLayout &DL) {
OpenPOWER on IntegriCloud