summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
diff options
context:
space:
mode:
authorPedro Artigas <partigas@apple.com>2012-11-30 22:07:05 +0000
committerPedro Artigas <partigas@apple.com>2012-11-30 22:07:05 +0000
commit993acd0c542ab951d568534749fcc71ecb4f55e6 (patch)
treeb273d8a414f52ba5289b6f636ee5926d30f00b45 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
parent22103e3416cfba9780fcd25c9182df5a8acae634 (diff)
downloadbcm5719-llvm-993acd0c542ab951d568534749fcc71ecb4f55e6.tar.gz
bcm5719-llvm-993acd0c542ab951d568534749fcc71ecb4f55e6.zip
Addresses many style issues with prior checkin (r169025)
llvm-svn: 169043
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp102
1 files changed, 44 insertions, 58 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index dc41e16469e..b0b9bac8f75 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -252,6 +252,42 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
return Changed ? &I : 0;
}
+//
+// Detect pattern:
+//
+// log2(Y*0.5)
+//
+// And check for corresponding fast math flags
+//
+
+static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) {
+ if (Op->hasOneUse()) {
+ if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op)) {
+ if (II->getIntrinsicID() == Intrinsic::log2 &&
+ II->hasUnsafeAlgebra()) {
+ Log2 = II;
+ Value *OpLog2Of = II->getArgOperand(0);
+ if (OpLog2Of->hasOneUse()) {
+ if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
+ if (I->getOpcode() == Instruction::FMul &&
+ I->hasUnsafeAlgebra()) {
+ ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
+ if (CFP && CFP->isExactlyValue(0.5)) {
+ Y = I->getOperand(1);
+ } else {
+ CFP = dyn_cast<ConstantFP>(I->getOperand(1));
+ if (CFP && CFP->isExactlyValue(0.5)) {
+ Y = I->getOperand(0);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
bool Changed = SimplifyAssociativeOrCommutative(I);
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
@@ -290,70 +326,20 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
Value *OpX = NULL;
Value *OpY = NULL;
IntrinsicInst *Log2;
- if (Op0->hasOneUse()) {
- if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op0)) {
- if (II->getIntrinsicID() == Intrinsic::log2 &&
- II->hasUnsafeAlgebra())
- {
- Log2 = II;
- Value *OpLog2Of = II->getArgOperand(0);
- if (OpLog2Of->hasOneUse()) {
- if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
- if (I->getOpcode() == Instruction::FMul &&
- I->hasUnsafeAlgebra())
- {
- ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
- if (CFP && CFP->isExactlyValue(0.5)) {
- OpY = I->getOperand(1);
- OpX = Op1;
- } else {
- CFP = dyn_cast<ConstantFP>(I->getOperand(1));
- if (CFP && CFP->isExactlyValue(0.5)) {
- OpY = I->getOperand(0);
- OpX = Op1;
- }
- }
- }
- }
- }
- }
- }
- }
- if (Op1->hasOneUse()) {
- if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op1)) {
- if (II->getIntrinsicID() == Intrinsic::log2 &&
- II->hasUnsafeAlgebra())
- {
- Log2 = II;
- Value *OpLog2Of = II->getArgOperand(0);
- if (OpLog2Of->hasOneUse()) {
- if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
- if (I->getOpcode() == Instruction::FMul &&
- I->hasUnsafeAlgebra())
- {
- ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
- if (CFP && CFP->isExactlyValue(0.5)) {
- OpY = I->getOperand(1);
- OpX = Op0;
- } else {
- CFP = dyn_cast<ConstantFP>(I->getOperand(1));
- if (CFP && CFP->isExactlyValue(0.5)) {
- OpY = I->getOperand(0);
- OpX = Op0;
- }
- }
- }
- }
- }
- }
+ detectLog2OfHalf(Op0, OpY, Log2);
+ if (OpY) {
+ OpX = Op1;
+ } else {
+ detectLog2OfHalf(Op1, OpY, Log2);
+ if (OpY) {
+ OpX = Op0;
}
}
// if pattern detected emit alternate sequence
if (OpX && OpY) {
Log2->setArgOperand(0, OpY);
Value *FMulVal = Builder->CreateFMul(OpX, Log2);
- Instruction *FMul = dyn_cast<Instruction>(FMulVal);
- assert(FMul && "Must be instruction as Log2 is instruction");
+ Instruction *FMul = cast<Instruction>(FMulVal);
FMul->copyFastMathFlags(Log2);
Instruction *FSub = BinaryOperator::CreateFSub(FMulVal, OpX);
FSub->copyFastMathFlags(Log2);
OpenPOWER on IntegriCloud