[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Apr 9 13:20:37 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.182 -> 1.183
---
Log message:
Implement select.ll:test11
---
Diffs of the changes: (+14 -5)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.182 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.183
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.182 Thu Apr 8 15:39:49 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Apr 9 13:19:44 2004
@@ -2055,11 +2055,20 @@
// Selecting between two constants?
if (Constant *TrueValC = dyn_cast<Constant>(TrueVal))
if (Constant *FalseValC = dyn_cast<Constant>(FalseVal)) {
- // If the true constant is a 1 and the false is a zero, turn this into a
- // cast from bool.
- if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) &&
- cast<ConstantInt>(TrueValC)->getRawValue() == 1)
- return new CastInst(CondVal, SI.getType());
+ if (SI.getType()->isInteger()) {
+ // select C, 1, 0 -> cast C to int
+ if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) &&
+ cast<ConstantInt>(TrueValC)->getRawValue() == 1) {
+ return new CastInst(CondVal, SI.getType());
+ } else if (TrueValC->isNullValue() && isa<ConstantInt>(FalseValC) &&
+ cast<ConstantInt>(FalseValC)->getRawValue() == 1) {
+ // select C, 0, 1 -> cast !C to int
+ Value *NotCond =
+ InsertNewInstBefore(BinaryOperator::createNot(CondVal,
+ "not."+CondVal->getName()), SI);
+ return new CastInst(NotCond, SI.getType());
+ }
+ }
}
return 0;
More information about the llvm-commits
mailing list