[llvm] r305651 - [Reassociate] Use APInt::isNullValue() instead of comparing with 0. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 18 11:15:39 PDT 2017


Author: ctopper
Date: Sun Jun 18 13:15:38 2017
New Revision: 305651

URL: http://llvm.org/viewvc/llvm-project?rev=305651&view=rev
Log:
[Reassociate] Use APInt::isNullValue() instead of comparing with 0. NFC

This should compile to slightly better code.

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=305651&r1=305650&r2=305651&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Sun Jun 18 13:15:38 2017
@@ -1136,7 +1136,7 @@ static Value *OptimizeAndOrXor(unsigned
 /// be returned.
 static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd, 
                              const APInt &ConstOpnd) {
-  if (ConstOpnd != 0) {
+  if (!ConstOpnd.isNullValue()) {
     if (!ConstOpnd.isAllOnesValue()) {
       LLVMContext &Ctx = Opnd->getType()->getContext();
       Instruction *I;
@@ -1163,7 +1163,7 @@ bool ReassociatePass::CombineXorOpnd(Ins
   //                       = ((x | c1) ^ c1) ^ (c1 ^ c2)
   //                       = (x & ~c1) ^ (c1 ^ c2)
   // It is useful only when c1 == c2.
-  if (Opnd1->isOrExpr() && Opnd1->getConstPart() != 0) {
+  if (Opnd1->isOrExpr() && !Opnd1->getConstPart().isNullValue()) {
     if (!Opnd1->getValue()->hasOneUse())
       return false;
 
@@ -1221,8 +1221,8 @@ bool ReassociatePass::CombineXorOpnd(Ins
     APInt C3((~C1) ^ C2);
 
     // Do not increase code size!
-    if (C3 != 0 && !C3.isAllOnesValue()) {
-      int NewInstNum = ConstOpnd != 0 ? 1 : 2;
+    if (!C3.isNullValue() && !C3.isAllOnesValue()) {
+      int NewInstNum = ConstOpnd.getBoolValue() ? 1 : 2;
       if (NewInstNum > DeadInstNum)
         return false;
     }
@@ -1238,8 +1238,8 @@ bool ReassociatePass::CombineXorOpnd(Ins
     APInt C3 = C1 ^ C2;
     
     // Do not increase code size
-    if (C3 != 0 && !C3.isAllOnesValue()) {
-      int NewInstNum = ConstOpnd != 0 ? 1 : 2;
+    if (!C3.isNullValue() && !C3.isAllOnesValue()) {
+      int NewInstNum = ConstOpnd.getBoolValue() ? 1 : 2;
       if (NewInstNum > DeadInstNum)
         return false;
     }
@@ -1327,7 +1327,8 @@ Value *ReassociatePass::OptimizeXor(Inst
     Value *CV;
 
     // Step 3.1: Try simplifying "CurrOpnd ^ ConstOpnd"
-    if (ConstOpnd != 0 && CombineXorOpnd(I, CurrOpnd, ConstOpnd, CV)) {
+    if (!ConstOpnd.isNullValue() &&
+        CombineXorOpnd(I, CurrOpnd, ConstOpnd, CV)) {
       Changed = true;
       if (CV)
         *CurrOpnd = XorOpnd(CV);
@@ -1369,7 +1370,7 @@ Value *ReassociatePass::OptimizeXor(Inst
       ValueEntry VE(getRank(O.getValue()), O.getValue());
       Ops.push_back(VE);
     }
-    if (ConstOpnd != 0) {
+    if (!ConstOpnd.isNullValue()) {
       Value *C = ConstantInt::get(Ty->getContext(), ConstOpnd);
       ValueEntry VE(getRank(C), C);
       Ops.push_back(VE);




More information about the llvm-commits mailing list