[llvm-commits] [llvm] r47313 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Mon Feb 18 22:12:18 PST 2008


Author: lattner
Date: Tue Feb 19 00:12:18 2008
New Revision: 47313

URL: http://llvm.org/viewvc/llvm-project?rev=47313&view=rev
Log:
fdiv/frem of undef can produce undef, because the undef operand 
can be a SNaN.  We could be more aggressive and turn this into 
unreachable, but that is less nice, and not really worth it.


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=47313&r1=47312&r2=47313&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Feb 19 00:12:18 2008
@@ -2590,9 +2590,13 @@
 Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
   Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
 
-  // undef / X -> 0
-  if (isa<UndefValue>(Op0))
+  // undef / X -> 0        for integer.
+  // undef / X -> undef    for FP (the undef could be a snan).
+  if (isa<UndefValue>(Op0)) {
+    if (Op0->getType()->isFPOrFPVector())
+      return ReplaceInstUsesWith(I, Op0);
     return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+  }
 
   // X / undef -> undef
   if (isa<UndefValue>(Op1))
@@ -2821,13 +2825,16 @@
 Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
   Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
 
-  // 0 % X == 0, we don't need to preserve faults!
+  // 0 % X == 0 for integer, we don't need to preserve faults!
   if (Constant *LHS = dyn_cast<Constant>(Op0))
     if (LHS->isNullValue())
       return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
 
-  if (isa<UndefValue>(Op0))              // undef % X -> 0
+  if (isa<UndefValue>(Op0)) {             // undef % X -> 0
+    if (I.getType()->isFPOrFPVector())
+      return ReplaceInstUsesWith(I, Op0);  // X % undef -> undef (could be SNaN)
     return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+  }
   if (isa<UndefValue>(Op1))
     return ReplaceInstUsesWith(I, Op1);  // X % undef -> undef
 





More information about the llvm-commits mailing list