summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2017-01-03 04:32:35 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2017-01-03 04:32:35 +0000
commitb264c949631770f3264ccc06877e3ab40c0ed360 (patch)
tree89501a1b6412aac1b6e36409ff0826073d3196c0 /llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
parent1cc294c85d7718d3333c9648467e70b221111b11 (diff)
downloadbcm5719-llvm-b264c949631770f3264ccc06877e3ab40c0ed360.tar.gz
bcm5719-llvm-b264c949631770f3264ccc06877e3ab40c0ed360.zip
InstCombine: Add fma with constant transforms
DAGCombine already does these. llvm-svn: 290860
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 029976e3133..e80b55320e7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1583,12 +1583,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
}
case Intrinsic::fma:
case Intrinsic::fmuladd: {
- Value *LHS = nullptr;
- Value *RHS = nullptr;
-
Value *Src0 = II->getArgOperand(0);
Value *Src1 = II->getArgOperand(1);
+ // Canonicalize constants into the RHS.
+ if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
+ II->setArgOperand(0, Src1);
+ II->setArgOperand(1, Src0);
+ std::swap(Src0, Src1);
+ }
+
+ Value *LHS = nullptr;
+ Value *RHS = nullptr;
+
// fma fneg(x), fneg(y), z -> fma x, y, z
if (match(Src0, m_FNeg(m_Value(LHS))) &&
match(Src1, m_FNeg(m_Value(RHS)))) {
@@ -1609,6 +1616,13 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
return replaceInstUsesWith(*II, NewCall);
}
+ // fma x, 1, z -> fadd x, z
+ if (match(Src1, m_FPOne())) {
+ Instruction *RI = BinaryOperator::CreateFAdd(Src0, II->getArgOperand(2));
+ RI->copyFastMathFlags(II);
+ return RI;
+ }
+
break;
}
case Intrinsic::ppc_altivec_lvx:
OpenPOWER on IntegriCloud