[llvm] r301741 - [ConstantRange] Use ternary operator instead of 'if' to avoid copying an APInt and then possibly copying over it.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 29 00:24:13 PDT 2017


Author: ctopper
Date: Sat Apr 29 02:24:13 2017
New Revision: 301741

URL: http://llvm.org/viewvc/llvm-project?rev=301741&view=rev
Log:
[ConstantRange] Use ternary operator instead of 'if' to avoid copying an APInt and then possibly copying over it.

Modified:
    llvm/trunk/lib/IR/ConstantRange.cpp

Modified: llvm/trunk/lib/IR/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantRange.cpp?rev=301741&r1=301740&r2=301741&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantRange.cpp (original)
+++ llvm/trunk/lib/IR/ConstantRange.cpp Sat Apr 29 02:24:13 2017
@@ -431,11 +431,8 @@ ConstantRange ConstantRange::unionWith(c
       return ConstantRange(CR.Lower, Upper);
     }
 
-    APInt L = Lower, U = Upper;
-    if (CR.Lower.ult(L))
-      L = CR.Lower;
-    if ((CR.Upper - 1).ugt(U - 1))
-      U = CR.Upper;
+    APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;
+    APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;
 
     if (L == 0 && U == 0)
       return ConstantRange(getBitWidth());
@@ -481,11 +478,8 @@ ConstantRange ConstantRange::unionWith(c
   if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper))
     return ConstantRange(getBitWidth());
 
-  APInt L = Lower, U = Upper;
-  if (CR.Upper.ugt(U))
-    U = CR.Upper;
-  if (CR.Lower.ult(L))
-    L = CR.Lower;
+  APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;
+  APInt U = CR.Upper.ugt(Upper) ? CR.Upper : Upper;
 
   return ConstantRange(std::move(L), std::move(U));
 }




More information about the llvm-commits mailing list