[InstCombine] Directly call computeOverflow methods in OptimizeOverflowCheck; NFC
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 10 Apr 2019 07:10:44 +0000 (07:10 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 10 Apr 2019 07:10:44 +0000 (07:10 +0000)
Instead of using the willOverflow helpers. This makes it easier to
extend handling of AlwaysOverflows.

llvm-svn: 358051

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

index 3c0ef7e..e274d7e 100644 (file)
@@ -3967,8 +3967,9 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
     if (match(RHS, m_Zero()))
       return SetResult(LHS, Builder.getFalse(), false);
 
+    OverflowResult OR;
     if (OCF == OCF_UNSIGNED_ADD) {
-      OverflowResult OR = computeOverflowForUnsignedAdd(LHS, RHS, &OrigI);
+      OR = computeOverflowForUnsignedAdd(LHS, RHS, &OrigI);
       if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNUWAdd(LHS, RHS), Builder.getFalse(),
                          true);
@@ -3976,7 +3977,8 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
       if (OR == OverflowResult::AlwaysOverflows)
         return SetResult(Builder.CreateAdd(LHS, RHS), Builder.getTrue(), true);
     } else {
-      if (willNotOverflowSignedAdd(LHS, RHS, OrigI))
+      OR = computeOverflowForSignedAdd(LHS, RHS, &OrigI);
+      if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNSWAdd(LHS, RHS), Builder.getFalse(),
                          true);
     }
@@ -3989,12 +3991,15 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
     if (match(RHS, m_Zero()))
       return SetResult(LHS, Builder.getFalse(), false);
 
+    OverflowResult OR;
     if (OCF == OCF_UNSIGNED_SUB) {
-      if (willNotOverflowUnsignedSub(LHS, RHS, OrigI))
+      OR = computeOverflowForUnsignedSub(LHS, RHS, &OrigI);
+      if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNUWSub(LHS, RHS), Builder.getFalse(),
                          true);
     } else {
-      if (willNotOverflowSignedSub(LHS, RHS, OrigI))
+      OR = computeOverflowForSignedSub(LHS, RHS, &OrigI);
+      if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNSWSub(LHS, RHS), Builder.getFalse(),
                          true);
     }
@@ -4015,15 +4020,17 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
     if (match(RHS, m_One()))
       return SetResult(LHS, Builder.getFalse(), false);
 
+    OverflowResult OR;
     if (OCF == OCF_UNSIGNED_MUL) {
-      OverflowResult OR = computeOverflowForUnsignedMul(LHS, RHS, &OrigI);
+      OR = computeOverflowForUnsignedMul(LHS, RHS, &OrigI);
       if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNUWMul(LHS, RHS), Builder.getFalse(),
                          true);
       if (OR == OverflowResult::AlwaysOverflows)
         return SetResult(Builder.CreateMul(LHS, RHS), Builder.getTrue(), true);
     } else {
-      if (willNotOverflowSignedMul(LHS, RHS, OrigI))
+      OR = computeOverflowForSignedMul(LHS, RHS, &OrigI);
+      if (OR == OverflowResult::NeverOverflows)
         return SetResult(Builder.CreateNSWMul(LHS, RHS), Builder.getFalse(),
                          true);
     }