Factor out code for computing umin and smin for SCEV expressions into
authorDan Gohman <gohman@apple.com>
Mon, 22 Jun 2009 03:18:45 +0000 (03:18 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 22 Jun 2009 03:18:45 +0000 (03:18 +0000)
helper functions. Based on a patch by Nick Lewycky.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73869 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/ScalarEvolution.h
lib/Analysis/ScalarEvolution.cpp

index 37f25fcf0cd6c3e9975d33b0663482f5fd1a9953..8d5136cea2c3f5b1f7403fbe733b13b4e47d6a0e 100644 (file)
@@ -494,6 +494,8 @@ namespace llvm {
     SCEVHandle getSMaxExpr(SmallVectorImpl<SCEVHandle> &Operands);
     SCEVHandle getUMaxExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
     SCEVHandle getUMaxExpr(SmallVectorImpl<SCEVHandle> &Operands);
+    SCEVHandle getSMinExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
+    SCEVHandle getUMinExpr(const SCEVHandle &LHS, const SCEVHandle &RHS);
     SCEVHandle getUnknown(Value *V);
     SCEVHandle getCouldNotCompute();
 
index d85191377f1d1780e2937b249aeb9f7264fa84d8..68aa595aa8dd80440eecb9f8663ac7acb8009225 100644 (file)
@@ -1903,6 +1903,18 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
   return Result;
 }
 
+SCEVHandle ScalarEvolution::getSMinExpr(const SCEVHandle &LHS,
+                                        const SCEVHandle &RHS) {
+  // ~smax(~x, ~y) == smin(x, y).
+  return getNotSCEV(getSMaxExpr(getNotSCEV(LHS), getNotSCEV(RHS)));
+}
+
+SCEVHandle ScalarEvolution::getUMinExpr(const SCEVHandle &LHS,
+                                        const SCEVHandle &RHS) {
+  // ~umax(~x, ~y) == umin(x, y)
+  return getNotSCEV(getUMaxExpr(getNotSCEV(LHS), getNotSCEV(RHS)));
+}
+
 SCEVHandle ScalarEvolution::getUnknown(Value *V) {
   if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
     return getConstant(CI);
@@ -2644,10 +2656,7 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) {
         if (LHS == U->getOperand(1) && RHS == U->getOperand(2))
           return getSMaxExpr(getSCEV(LHS), getSCEV(RHS));
         else if (LHS == U->getOperand(2) && RHS == U->getOperand(1))
-          // ~smax(~x, ~y) == smin(x, y).
-          return getNotSCEV(getSMaxExpr(
-                                   getNotSCEV(getSCEV(LHS)),
-                                   getNotSCEV(getSCEV(RHS))));
+          return getSMinExpr(getSCEV(LHS), getSCEV(RHS));
         break;
       case ICmpInst::ICMP_ULT:
       case ICmpInst::ICMP_ULE:
@@ -2658,9 +2667,7 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) {
         if (LHS == U->getOperand(1) && RHS == U->getOperand(2))
           return getUMaxExpr(getSCEV(LHS), getSCEV(RHS));
         else if (LHS == U->getOperand(2) && RHS == U->getOperand(1))
-          // ~umax(~x, ~y) == umin(x, y)
-          return getNotSCEV(getUMaxExpr(getNotSCEV(getSCEV(LHS)),
-                                        getNotSCEV(getSCEV(RHS))));
+          return getUMinExpr(getSCEV(LHS), getSCEV(RHS));
         break;
       case ICmpInst::ICMP_NE:
         // n != 0 ? n : 1  ->  umax(n, 1)