summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-04-10 22:21:27 +0000
committerChris Lattner <sabre@nondot.org>2004-04-10 22:21:27 +0000
commit623fba1107e217008547ae1367d759d88b194013 (patch)
tree1420d0d1152da4108abc6a8155b25a8a3811955a /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parent1f99df6d27e34a640e2b88145ce9156027184ab9 (diff)
downloadbcm5719-llvm-623fba1107e217008547ae1367d759d88b194013.tar.gz
bcm5719-llvm-623fba1107e217008547ae1367d759d88b194013.zip
Implement InstCombine/select.ll:test13*
llvm-svn: 12821
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 23d0f5ffcc7..56c52b3fb81 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2209,6 +2209,28 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return new CastInst(NotCond, SI.getType());
}
}
+
+ // See if we are selecting two values based on a comparison of the two values.
+ if (SetCondInst *SCI = dyn_cast<SetCondInst>(CondVal)) {
+ if (SCI->getOperand(0) == TrueVal && SCI->getOperand(1) == FalseVal) {
+ // Transform (X == Y) ? X : Y -> Y
+ if (SCI->getOpcode() == Instruction::SetEQ)
+ return ReplaceInstUsesWith(SI, FalseVal);
+ // Transform (X != Y) ? X : Y -> X
+ if (SCI->getOpcode() == Instruction::SetNE)
+ return ReplaceInstUsesWith(SI, TrueVal);
+ // NOTE: if we wanted to, this is where to detect MIN/MAX/ABS/etc.
+
+ } else if (SCI->getOperand(0) == FalseVal && SCI->getOperand(1) == TrueVal){
+ // Transform (X == Y) ? Y : X -> X
+ if (SCI->getOpcode() == Instruction::SetEQ)
+ return ReplaceInstUsesWith(SI, TrueVal);
+ // Transform (X != Y) ? Y : X -> Y
+ if (SCI->getOpcode() == Instruction::SetNE)
+ return ReplaceInstUsesWith(SI, FalseVal);
+ // NOTE: if we wanted to, this is where to detect MIN/MAX/ABS/etc.
+ }
+ }
// See if we can fold the select into one of our operands.
if (SI.getType()->isInteger()) {
OpenPOWER on IntegriCloud