[llvm-commits] CVS: llvm/lib/Transforms/Scalar/CondPropagate.cpp CorrelatedExprs.cpp InstructionCombining.cpp LoopUnswitch.cpp SCCP.cpp

Reid Spencer reid at x10sys.com
Thu Jan 11 20:25:22 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

CondPropagate.cpp updated: 1.13 -> 1.14
CorrelatedExprs.cpp updated: 1.46 -> 1.47
InstructionCombining.cpp updated: 1.591 -> 1.592
LoopUnswitch.cpp updated: 1.55 -> 1.56
SCCP.cpp updated: 1.149 -> 1.150
---
Log message:

Implement review feedback for the ConstantBool->ConstantInt merge. Chris
recommended that getBoolValue be replaced with getZExtValue and that
get(bool) be replaced by get(const Type*, uint64_t). This implements
those changes.


---
Diffs of the changes:  (+53 -43)

 CondPropagate.cpp        |    2 +-
 CorrelatedExprs.cpp      |   26 ++++++++++++++------------
 InstructionCombining.cpp |   47 ++++++++++++++++++++++++++++-------------------
 LoopUnswitch.cpp         |   13 +++++++------
 SCCP.cpp                 |    8 +++-----
 5 files changed, 53 insertions(+), 43 deletions(-)


Index: llvm/lib/Transforms/Scalar/CondPropagate.cpp
diff -u llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.13 llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.14
--- llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.13	Thu Jan 11 12:21:29 2007
+++ llvm/lib/Transforms/Scalar/CondPropagate.cpp	Thu Jan 11 22:24:45 2007
@@ -139,7 +139,7 @@
       // ultimate destination.
       bool PHIGone = PN->getNumIncomingValues() == 2;
       RevectorBlockTo(PN->getIncomingBlock(i-1),
-                      BI->getSuccessor(CB->getBoolValue() == 0));
+                      BI->getSuccessor(CB->getZExtValue() == 0));
       ++NumBrThread;
 
       // If there were two predecessors before this simplification, the PHI node


Index: llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp
diff -u llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.46 llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.47
--- llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.46	Thu Jan 11 12:21:29 2007
+++ llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp	Thu Jan 11 22:24:45 2007
@@ -472,7 +472,7 @@
     } else if (CmpInst *CI = dyn_cast<CmpInst>(I)) {
       Relation::KnownResult Res = getCmpResult(CI, NewRI);
       if (Res == Relation::Unknown) return false;
-      PropagateEquality(CI, ConstantInt::get(Res), NewRI);
+      PropagateEquality(CI, ConstantInt::get(Type::Int1Ty, Res), NewRI);
     } else {
       assert(isa<BranchInst>(*I) && "Unexpected instruction type!");
     }
@@ -488,7 +488,7 @@
 
     // Forward to the successor that corresponds to the branch we will take.
     ForwardSuccessorTo(TI, SuccNo, 
-                       BI->getSuccessor(!CB->getBoolValue()), NewRI);
+                       BI->getSuccessor(!CB->getZExtValue()), NewRI);
     return true;
   }
 
@@ -841,7 +841,7 @@
         // is true, this means that both operands to the OR are known to be true
         // as well.
         //
-        if (CB->getBoolValue() && Inst->getOpcode() == Instruction::And) {
+        if (CB->getZExtValue() && Inst->getOpcode() == Instruction::And) {
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
@@ -850,24 +850,26 @@
         // is false, this means that both operands to the OR are know to be false
         // as well.
         //
-        if (!CB->getBoolValue() && Inst->getOpcode() == Instruction::Or) {
+        if (!CB->getZExtValue() && Inst->getOpcode() == Instruction::Or) {
           PropagateEquality(Inst->getOperand(0), CB, RI);
           PropagateEquality(Inst->getOperand(1), CB, RI);
         }
 
-        // If we know that this instruction is a NOT instruction, we know that the
-        // operand is known to be the inverse of whatever the current value is.
+        // If we know that this instruction is a NOT instruction, we know that 
+        // the operand is known to be the inverse of whatever the current 
+        // value is.
         //
         if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
           if (BinaryOperator::isNot(BOp))
             PropagateEquality(BinaryOperator::getNotArgument(BOp),
-                              ConstantInt::get(!CB->getBoolValue()), RI);
+                              ConstantInt::get(Type::Int1Ty, 
+                                               !CB->getZExtValue()), RI);
 
         // If we know the value of a FCmp instruction, propagate the information
         // about the relation into this region as well.
         //
         if (FCmpInst *FCI = dyn_cast<FCmpInst>(Inst)) {
-          if (CB->getBoolValue()) {  // If we know the condition is true...
+          if (CB->getZExtValue()) {  // If we know the condition is true...
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(FCI->getPredicate(), FCI->getOperand(0),
                               FCI->getOperand(1), RI);
@@ -888,7 +890,7 @@
         // about the relation into this region as well.
         //
         if (ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
-          if (CB->getBoolValue()) { // If we know the condition is true...
+          if (CB->getZExtValue()) { // If we know the condition is true...
             // Propagate info about the LHS to the RHS & RHS to LHS
             PropagateRelation(ICI->getPredicate(), ICI->getOperand(0),
                               ICI->getOperand(1), RI);
@@ -994,7 +996,7 @@
     // See if we can figure out a result for this instruction...
     Relation::KnownResult Result = getCmpResult(CI, RI);
     if (Result != Relation::Unknown) {
-      PropagateEquality(CI, ConstantInt::get(Result != 0), RI);
+      PropagateEquality(CI, ConstantInt::get(Type::Int1Ty, Result != 0), RI);
     }
   }
 }
@@ -1068,7 +1070,7 @@
         DEBUG(cerr << "Replacing icmp with " << Result
                    << " constant: " << *CI);
 
-        CI->replaceAllUsesWith(ConstantInt::get((bool)Result));
+        CI->replaceAllUsesWith(ConstantInt::get(Type::Int1Ty, (bool)Result));
         // The instruction is now dead, remove it from the program.
         CI->getParent()->getInstList().erase(CI);
         ++NumCmpRemoved;
@@ -1122,7 +1124,7 @@
       if (Constant *Result = ConstantFoldInstruction(CI)) {
         // Wow, this is easy, directly eliminate the ICmpInst.
         DEBUG(cerr << "Replacing cmp with constant fold: " << *CI);
-        return cast<ConstantInt>(Result)->getBoolValue()
+        return cast<ConstantInt>(Result)->getZExtValue()
           ? Relation::KnownTrue : Relation::KnownFalse;
       }
     } else {


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.591 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.592
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.591	Thu Jan 11 12:21:29 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Jan 11 22:24:45 2007
@@ -2965,7 +2965,7 @@
                                            bool isSigned, bool Inside, 
                                            Instruction &IB) {
   assert(cast<ConstantInt>(ConstantExpr::getICmp((isSigned ? 
-            ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getBoolValue() &&
+            ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getZExtValue() &&
          "Lo is not <= Hi in range emission code!");
     
   if (Inside) {
@@ -3264,7 +3264,7 @@
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
-          if (cast<ConstantInt>(Cmp)->getBoolValue()) {
+          if (cast<ConstantInt>(Cmp)->getZExtValue()) {
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
@@ -3723,7 +3723,7 @@
             ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
           Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
           ICmpInst *LHS = cast<ICmpInst>(Op0);
-          if (cast<ConstantInt>(Cmp)->getBoolValue()) {
+          if (cast<ConstantInt>(Cmp)->getZExtValue()) {
             std::swap(LHS, RHS);
             std::swap(LHSCst, RHSCst);
             std::swap(LHSCC, RHSCC);
@@ -4152,7 +4152,8 @@
             EmitIt = false;  // This is indexing into a zero sized array?
           } else if (isa<ConstantInt>(C))
             return ReplaceInstUsesWith(I, // No comparison is needed here.
-                                 ConstantInt::get(Cond == ICmpInst::ICMP_NE));
+                                 ConstantInt::get(Type::Int1Ty, 
+                                                  Cond == ICmpInst::ICMP_NE));
         }
 
         if (EmitIt) {
@@ -4176,7 +4177,8 @@
         return InVal;
       else
         // No comparison is needed here, all indexes = 0
-        ReplaceInstUsesWith(I, ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
+        ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                Cond == ICmpInst::ICMP_EQ));
     }
 
     // Only lower this if the icmp is the only user of the GEP or if we expect
@@ -4253,7 +4255,8 @@
 
       if (NumDifferences == 0)   // SAME GEP?
         return ReplaceInstUsesWith(I, // No comparison is needed here.
-                                 ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
+                                   ConstantInt::get(Type::Int1Ty, 
+                                                    Cond == ICmpInst::ICMP_EQ));
       else if (NumDifferences == 1) {
         Value *LHSV = GEPLHS->getOperand(DiffOperand);
         Value *RHSV = GEPRHS->getOperand(DiffOperand);
@@ -4281,7 +4284,8 @@
 
   // fcmp pred X, X
   if (Op0 == Op1)
-    return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   isTrueWhenEqual(I)));
 
   if (isa<UndefValue>(Op1))                  // fcmp pred X, undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
@@ -4333,7 +4337,8 @@
 
   // icmp X, X
   if (Op0 == Op1)
-    return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   isTrueWhenEqual(I)));
 
   if (isa<UndefValue>(Op1))                  // X icmp undef -> undef
     return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
@@ -4343,7 +4348,8 @@
   if (GlobalValue *GV0 = dyn_cast<GlobalValue>(Op0))
     if (GlobalValue *GV1 = dyn_cast<GlobalValue>(Op1))
       if (!GV0->hasExternalWeakLinkage() || !GV1->hasExternalWeakLinkage())
-        return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
+        return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
+                                                       !isTrueWhenEqual(I)));
 
   // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
   // addresses never equal each other!  We already know that Op0 != Op1.
@@ -4351,7 +4357,8 @@
        isa<ConstantPointerNull>(Op0)) &&
       (isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) ||
        isa<ConstantPointerNull>(Op1)))
-    return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
+    return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                   !isTrueWhenEqual(I)));
 
   // icmp's with boolean values can always be turned into bitwise operations
   if (Ty == Type::Int1Ty) {
@@ -4691,7 +4698,7 @@
               ConstantExpr::getShl(ConstantExpr::getLShr(CI, ShAmt), ShAmt);
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
-              Constant *Cst = ConstantInt::get(IsICMP_NE);
+              Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
               return ReplaceInstUsesWith(I, Cst);
             }
 
@@ -4735,7 +4742,7 @@
 
             if (Comp != CI) {// Comparing against a bit that we know is zero.
               bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
-              Constant *Cst = ConstantInt::get(IsICMP_NE);
+              Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
               return ReplaceInstUsesWith(I, Cst);
             }
 
@@ -4957,7 +4964,8 @@
           if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
             Constant *NotCI = ConstantExpr::getNot(CI);
             if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())
-              return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
+              return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, 
+                                                             isICMP_NE));
           }
           break;
 
@@ -4967,7 +4975,8 @@
             // comparison can never succeed!
             if (!ConstantExpr::getAnd(CI,
                                       ConstantExpr::getNot(BOC))->isNullValue())
-              return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
+              return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
+                                                             isICMP_NE));
 
             // If we have ((X & C) == C), turn it into ((X & C) != 0).
             if (CI == BOC && isOneBitSet(CI))
@@ -6182,7 +6191,7 @@
           if (Op1CV && (Op1CV != (KnownZero^TypeMask))) {
             // (X&4) == 2 --> false
             // (X&4) != 2 --> true
-            Constant *Res = ConstantInt::get(isNE);
+            Constant *Res = ConstantInt::get(Type::Int1Ty, isNE);
             Res = ConstantExpr::getZExt(Res, CI.getType());
             return ReplaceInstUsesWith(CI, Res);
           }
@@ -6553,7 +6562,7 @@
   // select true, X, Y  -> X
   // select false, X, Y -> Y
   if (ConstantInt *C = dyn_cast<ConstantInt>(CondVal))
-    return ReplaceInstUsesWith(SI, C->getBoolValue() ? TrueVal : FalseVal);
+    return ReplaceInstUsesWith(SI, C->getZExtValue() ? TrueVal : FalseVal);
 
   // select C, X, X -> X
   if (TrueVal == FalseVal)
@@ -6574,7 +6583,7 @@
     ConstantInt *C;
     if ((C = dyn_cast<ConstantInt>(TrueVal)) && 
         C->getType() == Type::Int1Ty) {
-      if (C->getBoolValue()) {
+      if (C->getZExtValue()) {
         // Change: A = select B, true, C --> A = or B, C
         return BinaryOperator::createOr(CondVal, FalseVal);
       } else {
@@ -6586,7 +6595,7 @@
       }
     } else if ((C = dyn_cast<ConstantInt>(FalseVal)) &&
                C->getType() == Type::Int1Ty) {
-      if (C->getBoolValue() == false) {
+      if (C->getZExtValue() == false) {
         // Change: A = select B, C, false --> A = and B, C
         return BinaryOperator::createAnd(CondVal, TrueVal);
       } else {
@@ -9049,7 +9058,7 @@
   if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
     if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) &&
         BI->getCondition()->getType() == Type::Int1Ty) {
-      bool CondVal = cast<ConstantInt>(BI->getCondition())->getBoolValue();
+      bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue();
       AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList,
                                  TD);
       return;


Index: llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
diff -u llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.55 llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.56
--- llvm/lib/Transforms/Scalar/LoopUnswitch.cpp:1.55	Thu Jan 11 12:21:29 2007
+++ llvm/lib/Transforms/Scalar/LoopUnswitch.cpp	Thu Jan 11 22:24:46 2007
@@ -924,7 +924,8 @@
     if (IsEqual)
       Replacement = Val;
     else
-      Replacement = ConstantInt::get(!cast<ConstantInt>(Val)->getBoolValue());
+      Replacement = ConstantInt::get(Type::Int1Ty, 
+                                     !cast<ConstantInt>(Val)->getZExtValue());
     
     for (unsigned i = 0, e = Users.size(); i != e; ++i)
       if (Instruction *U = cast<Instruction>(Users[i])) {
@@ -1026,7 +1027,7 @@
     switch (I->getOpcode()) {
     case Instruction::Select:
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(0))) {
-        ReplaceUsesOfWith(I, I->getOperand(!CB->getBoolValue()+1), Worklist);
+        ReplaceUsesOfWith(I, I->getOperand(!CB->getZExtValue()+1), Worklist);
         continue;
       }
       break;
@@ -1036,7 +1037,7 @@
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1))) 
         if (CB->getType() == Type::Int1Ty) {
-          if (CB->getBoolValue())   // X & 1 -> X
+          if (CB->getZExtValue())   // X & 1 -> X
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
           else                  // X & 0 -> 0
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
@@ -1049,7 +1050,7 @@
         cast<BinaryOperator>(I)->swapOperands();
       if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
         if (CB->getType() == Type::Int1Ty) {
-          if (CB->getBoolValue())   // X | 1 -> 1
+          if (CB->getZExtValue())   // X | 1 -> 1
             ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
           else                  // X | 0 -> X
             ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
@@ -1094,8 +1095,8 @@
         break;  // FIXME: Enable.
 
         DOUT << "Folded branch: " << *BI;
-        BasicBlock *DeadSucc = BI->getSuccessor(CB->getBoolValue());
-        BasicBlock *LiveSucc = BI->getSuccessor(!CB->getBoolValue());
+        BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue());
+        BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue());
         DeadSucc->removePredecessor(BI->getParent(), true);
         Worklist.push_back(new BranchInst(LiveSucc, BI));
         BI->eraseFromParent();


Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.149 llvm/lib/Transforms/Scalar/SCCP.cpp:1.150
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.149	Thu Jan 11 12:21:29 2007
+++ llvm/lib/Transforms/Scalar/SCCP.cpp	Thu Jan 11 22:24:46 2007
@@ -416,8 +416,7 @@
     } else {
       LatticeVal &BCValue = getValueState(BI->getCondition());
       if (BCValue.isOverdefined() ||
-          (BCValue.isConstant() && 
-          BCValue.getConstant()->getType() != Type::Int1Ty)) {
+          (BCValue.isConstant() && !isa<ConstantInt>(BCValue.getConstant()))) {
         // Overdefined condition variables, and branches on unfoldable constant
         // conditions, mean the branch could go either way.
         Succs[0] = Succs[1] = true;
@@ -647,10 +646,9 @@
   LatticeVal &CondValue = getValueState(I.getCondition());
   if (CondValue.isUndefined())
     return;
-  if (CondValue.isConstant() &&
-      CondValue.getConstant()->getType() == Type::Int1Ty) {
+  if (CondValue.isConstant()) {
     if (ConstantInt *CondCB = dyn_cast<ConstantInt>(CondValue.getConstant())){
-      mergeInValue(&I, getValueState(CondCB->getBoolValue() ? I.getTrueValue()
+      mergeInValue(&I, getValueState(CondCB->getZExtValue() ? I.getTrueValue()
                                                           : I.getFalseValue()));
       return;
     }






More information about the llvm-commits mailing list