summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-12-05 01:26:29 +0000
committerChris Lattner <sabre@nondot.org>2006-12-05 01:26:29 +0000
commitc209b584eb3ad9d302e2fa71c117d444fa8d922a (patch)
tree1d989577ee5aa22ea0e07b2b5fe1e5be29d36e81 /llvm/lib/Transforms
parent21efc73161ea59756f2dcd0ca5976209f7cc9dac (diff)
downloadbcm5719-llvm-c209b584eb3ad9d302e2fa71c117d444fa8d922a.tar.gz
bcm5719-llvm-c209b584eb3ad9d302e2fa71c117d444fa8d922a.zip
add an instcombine xform. This speeds up 462.libquantum from 9.78s to
7.48s. This regression is due to unforseen consequences of the cast patch. llvm-svn: 32209
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index fac659f39b8..b12c6b58414 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -6023,6 +6023,23 @@ Instruction *InstCombiner::visitTrunc(CastInst &CI) {
Value *V = InsertCastBefore(SrcI->getOperand(0), Ty, CI);
return new ShiftInst(Instruction::LShr, V, SrcI->getOperand(1));
}
+ } else { // This is a variable shr.
+
+ // Turn 'trunc (lshr X, Y) to bool' into '(X & (1 << Y)) != 0'. This is
+ // more LLVM instructions, but allows '1 << Y' to be hoisted if
+ // loop-invariant and CSE'd.
+ if (CI.getType() == Type::BoolTy && SrcI->hasOneUse()) {
+ Value *One = ConstantInt::get(SrcI->getType(), 1);
+
+ Value *V = InsertNewInstBefore(new ShiftInst(Instruction::Shl, One,
+ SrcI->getOperand(1),
+ "tmp"), CI);
+ V = InsertNewInstBefore(BinaryOperator::createAnd(V,
+ SrcI->getOperand(0),
+ "tmp"), CI);
+ Value *Zero = Constant::getNullValue(V->getType());
+ return BinaryOperator::createSetNE(V, Zero);
+ }
}
break;
}
OpenPOWER on IntegriCloud