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

Chris Lattner lattner at cs.uiuc.edu
Wed Jul 20 11:49:39 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.358 -> 1.359
---
Log message:

Do not let MaskedValueIsZero consider undef to be zero, for reasons
explained in the comment.

This fixes UnitTests/2003-09-18-BitFieldTest on darwin


---
Diffs of the changes:  (+8 -2)

 InstructionCombining.cpp |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.358 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.359
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.358	Mon Jul 18 18:07:33 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Jul 20 13:49:28 2005
@@ -1317,7 +1317,13 @@
 /// this predicate to simplify operations downstream.  V and Mask are known to
 /// be the same type.
 static bool MaskedValueIsZero(Value *V, ConstantIntegral *Mask) {
-  if (isa<UndefValue>(V) || Mask->isNullValue())
+  // Note, we cannot consider 'undef' to be "IsZero" here.  The problem is that
+  // we cannot optimize based on the assumption that it is zero without changing
+  // to to an explicit zero.  If we don't change it to zero, other code could 
+  // optimized based on the contradictory assumption that it is non-zero.
+  // Because instcombine aggressively folds operations with undef args anyway,
+  // this won't lose us code quality.
+  if (Mask->isNullValue())
     return true;
   if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V))
     return ConstantExpr::getAnd(CI, Mask)->isNullValue();
@@ -3134,7 +3140,7 @@
       return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
   }
   if (isa<UndefValue>(Op1)) {
-    if (isLeftShift || I.getType()->isUnsigned())
+    if (isLeftShift || I.getType()->isUnsigned())// X << undef, X >>u undef -> 0
       return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
     else
       return ReplaceInstUsesWith(I, Op0);          // X >>s undef -> X






More information about the llvm-commits mailing list