mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	Move LSR's private isZero function to a public SCEV member
function, and make use of it in several places. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -81,6 +81,10 @@ namespace llvm {
 | 
				
			|||||||
    /// 
 | 
					    /// 
 | 
				
			||||||
    uint32_t getBitWidth() const;
 | 
					    uint32_t getBitWidth() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// isZero - Return true if the expression is a constant zero.
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    bool isZero() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// replaceSymbolicValuesWithConcrete - If this SCEV internally references
 | 
					    /// replaceSymbolicValuesWithConcrete - If this SCEV internally references
 | 
				
			||||||
    /// the symbolic value "Sym", construct and return a new SCEV that produces
 | 
					    /// the symbolic value "Sym", construct and return a new SCEV that produces
 | 
				
			||||||
    /// the same value, but which uses the concrete value Conc instead of the
 | 
					    /// the same value, but which uses the concrete value Conc instead of the
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -132,6 +132,12 @@ uint32_t SCEV::getBitWidth() const {
 | 
				
			|||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool SCEV::isZero() const {
 | 
				
			||||||
 | 
					  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
 | 
				
			||||||
 | 
					    return SC->getValue()->isZero();
 | 
				
			||||||
 | 
					  return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
 | 
					SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1136,8 +1142,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
 | 
				
			|||||||
                               const Loop *L) {
 | 
					                               const Loop *L) {
 | 
				
			||||||
  if (Operands.size() == 1) return Operands[0];
 | 
					  if (Operands.size() == 1) return Operands[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (SCEVConstant *StepC = dyn_cast<SCEVConstant>(Operands.back()))
 | 
					  if (Operands.back()->isZero()) {
 | 
				
			||||||
    if (StepC->getValue()->isZero()) {
 | 
					 | 
				
			||||||
    Operands.pop_back();
 | 
					    Operands.pop_back();
 | 
				
			||||||
    return getAddRecExpr(Operands, L);             // { X,+,0 }  -->  X
 | 
					    return getAddRecExpr(Operands, L);             // { X,+,0 }  -->  X
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -2583,8 +2588,7 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) {
 | 
				
			|||||||
        // value at this index.  When solving for "X*X != 5", for example, we
 | 
					        // value at this index.  When solving for "X*X != 5", for example, we
 | 
				
			||||||
        // should not accept a root of 2.
 | 
					        // should not accept a root of 2.
 | 
				
			||||||
        SCEVHandle Val = AddRec->evaluateAtIteration(R1, SE);
 | 
					        SCEVHandle Val = AddRec->evaluateAtIteration(R1, SE);
 | 
				
			||||||
        if (SCEVConstant *EvalVal = dyn_cast<SCEVConstant>(Val))
 | 
					        if (Val->isZero())
 | 
				
			||||||
          if (EvalVal->getValue()->isZero())
 | 
					 | 
				
			||||||
          return R1;  // We found a quadratic root!
 | 
					          return R1;  // We found a quadratic root!
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -126,8 +126,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
 | 
				
			|||||||
  assert(Ty->isInteger() && "Cannot expand fp recurrences yet!");
 | 
					  assert(Ty->isInteger() && "Cannot expand fp recurrences yet!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // {X,+,F} --> X + {0,+,F}
 | 
					  // {X,+,F} --> X + {0,+,F}
 | 
				
			||||||
  if (!isa<SCEVConstant>(S->getStart()) ||
 | 
					  if (!S->getStart()->isZero()) {
 | 
				
			||||||
      !cast<SCEVConstant>(S->getStart())->getValue()->isZero()) {
 | 
					 | 
				
			||||||
    Value *Start = expand(S->getStart());
 | 
					    Value *Start = expand(S->getStart());
 | 
				
			||||||
    std::vector<SCEVHandle> NewOps(S->op_begin(), S->op_end());
 | 
					    std::vector<SCEVHandle> NewOps(S->op_begin(), S->op_end());
 | 
				
			||||||
    NewOps[0] = SE.getIntegerSCEV(0, Ty);
 | 
					    NewOps[0] = SE.getIntegerSCEV(0, Ty);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -586,8 +586,7 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEVHandle &NewBase,
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // If there is no immediate value, skip the next part.
 | 
					  // If there is no immediate value, skip the next part.
 | 
				
			||||||
  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm))
 | 
					  if (Imm->isZero())
 | 
				
			||||||
    if (SC->getValue()->isZero())
 | 
					 | 
				
			||||||
    return Rewriter.expandCodeFor(NewBase, BaseInsertPt);
 | 
					    return Rewriter.expandCodeFor(NewBase, BaseInsertPt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Value *Base = Rewriter.expandCodeFor(NewBase, BaseInsertPt);
 | 
					  Value *Base = Rewriter.expandCodeFor(NewBase, BaseInsertPt);
 | 
				
			||||||
@@ -891,8 +890,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      SeparateSubExprs(SubExprs, SARE->getOperand(0), SE);
 | 
					      SeparateSubExprs(SubExprs, SARE->getOperand(0), SE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else if (!isa<SCEVConstant>(Expr) ||
 | 
					  } else if (!Expr->isZero()) {
 | 
				
			||||||
             !cast<SCEVConstant>(Expr)->getValue()->isZero()) {
 | 
					 | 
				
			||||||
    // Do not add zero.
 | 
					    // Do not add zero.
 | 
				
			||||||
    SubExprs.push_back(Expr);
 | 
					    SubExprs.push_back(Expr);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -979,14 +977,6 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses,
 | 
				
			|||||||
  return Result;
 | 
					  return Result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// isZero - returns true if the scalar evolution expression is zero.
 | 
					 | 
				
			||||||
///
 | 
					 | 
				
			||||||
static bool isZero(const SCEVHandle &V) {
 | 
					 | 
				
			||||||
  if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
 | 
					 | 
				
			||||||
    return SC->getValue()->isZero();
 | 
					 | 
				
			||||||
  return false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// ValidStride - Check whether the given Scale is valid for all loads and 
 | 
					/// ValidStride - Check whether the given Scale is valid for all loads and 
 | 
				
			||||||
/// stores in UsersToProcess.
 | 
					/// stores in UsersToProcess.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
@@ -1009,7 +999,7 @@ bool LoopStrengthReduce::ValidStride(bool HasBaseReg,
 | 
				
			|||||||
    TargetLowering::AddrMode AM;
 | 
					    TargetLowering::AddrMode AM;
 | 
				
			||||||
    if (SCEVConstant *SC = dyn_cast<SCEVConstant>(UsersToProcess[i].Imm))
 | 
					    if (SCEVConstant *SC = dyn_cast<SCEVConstant>(UsersToProcess[i].Imm))
 | 
				
			||||||
      AM.BaseOffs = SC->getValue()->getSExtValue();
 | 
					      AM.BaseOffs = SC->getValue()->getSExtValue();
 | 
				
			||||||
    AM.HasBaseReg = HasBaseReg || !isZero(UsersToProcess[i].Base);
 | 
					    AM.HasBaseReg = HasBaseReg || !UsersToProcess[i].Base->isZero();
 | 
				
			||||||
    AM.Scale = Scale;
 | 
					    AM.Scale = Scale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If load[imm+r*scale] is illegal, bail out.
 | 
					    // If load[imm+r*scale] is illegal, bail out.
 | 
				
			||||||
@@ -1069,7 +1059,7 @@ unsigned LoopStrengthReduce::CheckForIVReuse(bool HasBaseReg,
 | 
				
			|||||||
               IE = SI->second.IVs.end(); II != IE; ++II)
 | 
					               IE = SI->second.IVs.end(); II != IE; ++II)
 | 
				
			||||||
          // FIXME: Only handle base == 0 for now.
 | 
					          // FIXME: Only handle base == 0 for now.
 | 
				
			||||||
          // Only reuse previous IV if it would not require a type conversion.
 | 
					          // Only reuse previous IV if it would not require a type conversion.
 | 
				
			||||||
          if (isZero(II->Base) &&
 | 
					          if (II->Base->isZero() &&
 | 
				
			||||||
              !RequiresTypeConversion(II->Base->getType(), Ty)) {
 | 
					              !RequiresTypeConversion(II->Base->getType(), Ty)) {
 | 
				
			||||||
            IV = *II;
 | 
					            IV = *II;
 | 
				
			||||||
            return Scale;
 | 
					            return Scale;
 | 
				
			||||||
@@ -1233,7 +1223,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
 | 
				
			|||||||
  // their value in a register and add it in for each use. This will take up
 | 
					  // their value in a register and add it in for each use. This will take up
 | 
				
			||||||
  // a register operand, which potentially restricts what stride values are
 | 
					  // a register operand, which potentially restricts what stride values are
 | 
				
			||||||
  // valid.
 | 
					  // valid.
 | 
				
			||||||
  bool HaveCommonExprs = !isZero(CommonExprs);
 | 
					  bool HaveCommonExprs = !CommonExprs->isZero();
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // If all uses are addresses, check if it is possible to reuse an IV with a
 | 
					  // If all uses are addresses, check if it is possible to reuse an IV with a
 | 
				
			||||||
  // stride that is a factor of this stride. And that the multiple is a number
 | 
					  // stride that is a factor of this stride. And that the multiple is a number
 | 
				
			||||||
@@ -1629,7 +1619,7 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
 | 
				
			|||||||
      // Avoid rewriting the compare instruction with an iv of new stride
 | 
					      // Avoid rewriting the compare instruction with an iv of new stride
 | 
				
			||||||
      // if it's likely the new stride uses will be rewritten using the
 | 
					      // if it's likely the new stride uses will be rewritten using the
 | 
				
			||||||
      if (AllUsesAreAddresses &&
 | 
					      if (AllUsesAreAddresses &&
 | 
				
			||||||
          ValidStride(!isZero(CommonExprs), Scale, UsersToProcess)) {        
 | 
					          ValidStride(!CommonExprs->isZero(), Scale, UsersToProcess)) {
 | 
				
			||||||
        NewCmpVal = CmpVal;
 | 
					        NewCmpVal = CmpVal;
 | 
				
			||||||
        continue;
 | 
					        continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user