[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Apr 10 17:22:33 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.187 -> 1.188

---
Log message:

Implement InstCombine/select.ll:test13*


---
Diffs of the changes:  (+22 -0)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.187 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.188
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.187	Sat Apr 10 17:01:55 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Apr 10 17:21:27 2004
@@ -2209,6 +2209,28 @@
         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()) {





More information about the llvm-commits mailing list