Add a getUMinFromMismatchedTypes helper function.
authorDan Gohman <gohman@apple.com>
Mon, 22 Jun 2009 15:03:27 +0000 (15:03 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 22 Jun 2009 15:03:27 +0000 (15:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73883 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8d5136cea2c3f5b1f7403fbe733b13b4e47d6a0e..d73c30fb07c739ed2542a58b503eba7999684cce 100644 (file)
@@ -553,6 +553,12 @@ namespace llvm {
     SCEVHandle getUMaxFromMismatchedTypes(const SCEVHandle &LHS,
                                           const SCEVHandle &RHS);
 
+    /// getUMinFromMismatchedTypes - Promote the operands to the wider of
+    /// the types using zero-extension, and then perform a umin operation
+    /// with them.
+    SCEVHandle getUMinFromMismatchedTypes(const SCEVHandle &LHS,
+                                          const SCEVHandle &RHS);
+
     /// hasSCEV - Return true if the SCEV for this value has already been
     /// computed.
     bool hasSCEV(Value *V) const;
index 68aa595aa8dd80440eecb9f8663ac7acb8009225..d67761c60a3fd745f3f1c9d50dd3af14028401b4 100644 (file)
@@ -2156,6 +2156,22 @@ SCEVHandle ScalarEvolution::getUMaxFromMismatchedTypes(const SCEVHandle &LHS,
   return getUMaxExpr(PromotedLHS, PromotedRHS);
 }
 
+/// getUMinFromMismatchedTypes - Promote the operands to the wider of
+/// the types using zero-extension, and then perform a umin operation
+/// with them.
+SCEVHandle ScalarEvolution::getUMinFromMismatchedTypes(const SCEVHandle &LHS,
+                                                       const SCEVHandle &RHS) {
+  SCEVHandle PromotedLHS = LHS;
+  SCEVHandle PromotedRHS = RHS;
+
+  if (getTypeSizeInBits(LHS->getType()) > getTypeSizeInBits(RHS->getType()))
+    PromotedRHS = getZeroExtendExpr(RHS, LHS->getType());
+  else
+    PromotedLHS = getNoopOrZeroExtend(LHS, RHS->getType());
+
+  return getUMinExpr(PromotedLHS, PromotedRHS);
+}
+
 /// ReplaceSymbolicValueWithConcrete - This looks up the computed SCEV value for
 /// the specified instruction and replaces any references to the symbolic value
 /// SymName with the specified value.  This is used during PHI resolution.