[llvm-commits] [llvm] r124496 - /llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Duncan Sands baldrick at free.fr
Fri Jan 28 10:50:50 PST 2011


Author: baldrick
Date: Fri Jan 28 12:50:50 2011
New Revision: 124496

URL: http://llvm.org/viewvc/llvm-project?rev=124496&view=rev
Log:
Thread divisions over selects and phis.  This doesn't fire much and has basically
zero effect on the testsuite (it improves two Ada testcases).

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=124496&r1=124495&r2=124496&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri Jan 28 12:50:50 2011
@@ -759,6 +759,8 @@
     }
   }
 
+  bool isSigned = Opcode == Instruction::SDiv;
+
   // X / undef -> undef
   if (isa<UndefValue>(Op1))
     return Op1;
@@ -795,7 +797,6 @@
     if (Y != Op1) std::swap(X, Y); // Ensure expression is (X * Y) / Y, Y = Op1
     BinaryOperator *Mul = dyn_cast<BinaryOperator>(Op0);
     // If the Mul knows it does not overflow, then we are good to go.
-    bool isSigned = Opcode == Instruction::SDiv;
     if ((isSigned && Mul->hasNoSignedWrap()) ||
         (!isSigned && Mul->hasNoUnsignedWrap()))
       return X;
@@ -805,6 +806,23 @@
         return X;
   }
 
+  // (X rem Y) / Y -> 0
+  if ((isSigned && match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) ||
+      (!isSigned && match(Op0, m_URem(m_Value(), m_Specific(Op1)))))
+    return Constant::getNullValue(Op0->getType());
+
+  // If the operation is with the result of a select instruction, check whether
+  // operating on either branch of the select always yields the same value.
+  if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
+    if (Value *V = ThreadBinOpOverSelect(Opcode, Op0, Op1, TD, DT, MaxRecurse))
+      return V;
+
+  // If the operation is with the result of a phi instruction, check whether
+  // operating on all incoming values of the phi always yields the same value.
+  if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
+    if (Value *V = ThreadBinOpOverPHI(Opcode, Op0, Op1, TD, DT, MaxRecurse))
+      return V;
+
   return 0;
 }
 
@@ -815,10 +833,6 @@
   if (Value *V = SimplifyDiv(Instruction::SDiv, Op0, Op1, TD, DT, MaxRecurse))
     return V;
 
-  // (X rem Y) / Y -> 0
-  if (match(Op0, m_SRem(m_Value(), m_Specific(Op1))))
-    return Constant::getNullValue(Op0->getType());
-
   return 0;
 }
 
@@ -834,10 +848,6 @@
   if (Value *V = SimplifyDiv(Instruction::UDiv, Op0, Op1, TD, DT, MaxRecurse))
     return V;
 
-  // (X rem Y) / Y -> 0
-  if (match(Op0, m_URem(m_Value(), m_Specific(Op1))))
-    return Constant::getNullValue(Op0->getType());
-
   return 0;
 }
 





More information about the llvm-commits mailing list