[llvm-commits] [llvm] r46429 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-01-27-FloatSelect.ll

Chris Lattner sabre at nondot.org
Sun Jan 27 16:58:18 PST 2008


Author: lattner
Date: Sun Jan 27 18:58:18 2008
New Revision: 46429

URL: http://llvm.org/viewvc/llvm-project?rev=46429&view=rev
Log:
Fix PR1932 by disabling an xform invalid for fdiv.

Added:
    llvm/trunk/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=46429&r1=46428&r2=46429&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Jan 27 18:58:18 2008
@@ -2494,14 +2494,15 @@
   if (isa<UndefValue>(Op1))
     return ReplaceInstUsesWith(I, Op1);
 
-  // Handle cases involving: div X, (select Cond, Y, Z)
+  // Handle cases involving: [su]div X, (select Cond, Y, Z)
+  // This does not apply for fdiv.
   if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) {
-    // div X, (Cond ? 0 : Y) -> div X, Y.  If the div and the select are in the
-    // same basic block, then we replace the select with Y, and the condition 
-    // of the select with false (if the cond value is in the same BB).  If the
-    // select has uses other than the div, this allows them to be simplified
-    // also. Note that div X, Y is just as good as div X, 0 (undef)
-    if (Constant *ST = dyn_cast<Constant>(SI->getOperand(1)))
+    // [su]div X, (Cond ? 0 : Y) -> div X, Y.  If the div and the select are in
+    // the same basic block, then we replace the select with Y, and the
+    // condition of the select with false (if the cond value is in the same BB).
+    // If the select has uses other than the div, this allows them to be
+    // simplified also. Note that div X, Y is just as good as div X, 0 (undef)
+    if (ConstantInt *ST = dyn_cast<ConstantInt>(SI->getOperand(1)))
       if (ST->isNullValue()) {
         Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
         if (CondI && CondI->getParent() == I.getParent())
@@ -2513,8 +2514,8 @@
         return &I;
       }
 
-    // Likewise for: div X, (Cond ? Y : 0) -> div X, Y
-    if (Constant *ST = dyn_cast<Constant>(SI->getOperand(2)))
+    // Likewise for: [su]div X, (Cond ? Y : 0) -> div X, Y
+    if (ConstantInt *ST = dyn_cast<ConstantInt>(SI->getOperand(2)))
       if (ST->isNullValue()) {
         Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
         if (CondI && CondI->getParent() == I.getParent())

Added: llvm/trunk/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll?rev=46429&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll Sun Jan 27 18:58:18 2008
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep select
+
+define double @fold(i1 %a, double %b) {
+%s = select i1 %a, double 0., double 1.
+%c = fdiv double %b, %s
+ret double %c
+}





More information about the llvm-commits mailing list