aboutsummaryrefslogtreecommitdiffstats
path: root/lib
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
commitd76956d4441e790828571778281671c677078576 (patch)
tree9fa1eaf7092aa0bc9681cc4ba1ae60222d16d42e /lib
parentfb384a15fff3d910e4cc5ff8fcd083f76c5dfd70 (diff)
downloadexternal_llvm-d76956d4441e790828571778281671c677078576.zip
external_llvm-d76956d4441e790828571778281671c677078576.tar.gz
external_llvm-d76956d4441e790828571778281671c677078576.tar.bz2
Implement InstCombine/select.ll:test13*
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12821 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 23d0f5f..56c52b3 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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()) {