OSDN Git Service

[ValueTracking] Change if-else chain into switch in computeKnownBitsFromAssume
authorSander de Smalen <sander.desmalen@arm.com>
Thu, 11 Apr 2019 13:02:19 +0000 (13:02 +0000)
committerSander de Smalen <sander.desmalen@arm.com>
Thu, 11 Apr 2019 13:02:19 +0000 (13:02 +0000)
This is a follow-up patch to D60504 to further improve
performance issues in computeKnownBitsFromAssume.

The patch is NFC, but may improve compile-time performance
if the compiler isn't clever enough to do the optimization
itself.

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

lib/Analysis/ValueTracking.cpp

index f51d5ab..4bb4d30 100644 (file)
@@ -625,7 +625,10 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
 
     CmpInst::Predicate Pred;
     uint64_t C;
-    if (Cmp->getPredicate() == ICmpInst::ICMP_EQ) {
+    switch (Cmp->getPredicate()) {
+    default:
+      break;
+    case ICmpInst::ICMP_EQ:
       // assume(v = a)
       if (match(Cmp, m_c_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -762,7 +765,8 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
         Known.Zero |= RHSKnown.One  << C;
         Known.One  |= RHSKnown.Zero << C;
       }
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_SGE) {
+      break;
+    case ICmpInst::ICMP_SGE:
       // assume(v >=_s c) where c is non-negative
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -774,7 +778,8 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
           Known.makeNonNegative();
         }
       }
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_SGT) {
+      break;
+    case ICmpInst::ICMP_SGT:
       // assume(v >_s c) where c is at least -1.
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -786,7 +791,8 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
           Known.makeNonNegative();
         }
       }
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_SLE) {
+      break;
+    case ICmpInst::ICMP_SLE:
       // assume(v <=_s c) where c is negative
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -798,7 +804,8 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
           Known.makeNegative();
         }
       }
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_SLT) {
+      break;
+    case ICmpInst::ICMP_SLT:
       // assume(v <_s c) where c is non-positive
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -810,8 +817,9 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
           Known.makeNegative();
         }
       }
-    // assume(v <=_u c)
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_ULE) {
+      break;
+    case ICmpInst::ICMP_ULE:
+      // assume(v <=_u c)
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
         KnownBits RHSKnown(BitWidth);
@@ -820,8 +828,9 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
         // Whatever high bits in c are zero are known to be zero.
         Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
       }
+      break;
+    case ICmpInst::ICMP_ULT:
       // assume(v <_u c)
-    } else if (Cmp->getPredicate() == ICmpInst::ICMP_ULT) {
       if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
           isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
         KnownBits RHSKnown(BitWidth);
@@ -842,6 +851,7 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
         else
           Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
       }
+      break;
     }
   }