@@ -263,8 +263,6 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
263263 // Cache the DataLayout since we use it a lot.
264264 const DataLayout &DL;
265265
266- DominatorTree DT;
267-
268266 // / The OptimizationRemarkEmitter available for this compilation.
269267 OptimizationRemarkEmitter *ORE;
270268
@@ -1691,9 +1689,8 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
16911689 // Make sure that the callsite is recursive:
16921690 if (CandidateCall.getCaller () != &F)
16931691 return false ;
1694- CallInst *CallInstr = dyn_cast<CallInst>(&CandidateCall);
16951692 // Only handle the case when the callsite has a single predecessor:
1696- auto *CallBB = CallInstr-> getParent ();
1693+ auto *CallBB = CandidateCall. getParent ();
16971694 auto *Predecessor = CallBB->getSinglePredecessor ();
16981695 if (!Predecessor)
16991696 return false ;
@@ -1707,9 +1704,9 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
17071704 bool ArgFound = false ;
17081705 Value *FuncArg = nullptr , *CallArg = nullptr ;
17091706 for (unsigned ArgNum = 0 ;
1710- ArgNum < F.arg_size () && ArgNum < CallInstr-> arg_size (); ArgNum++) {
1707+ ArgNum < F.arg_size () && ArgNum < CandidateCall. arg_size (); ArgNum++) {
17111708 FuncArg = F.getArg (ArgNum);
1712- CallArg = CallInstr-> getArgOperand (ArgNum);
1709+ CallArg = CandidateCall. getArgOperand (ArgNum);
17131710 if (FuncArg == CmpOp && CallArg != CmpOp) {
17141711 ArgFound = true ;
17151712 break ;
@@ -1721,17 +1718,17 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
17211718 // Now we have a recursive call that is guarded by a cmp instruction.
17221719 // Check if this cmp can be simplified:
17231720 SimplifyQuery SQ (DL, dyn_cast<Instruction>(CallArg));
1724- CondContext CC (cast<Value>( &Cmp) );
1725- CC.CondIsTrue = CallBB == Br->getSuccessor (0 );
1721+ CondContext CC (&Cmp);
1722+ CC.Invert = ( CallBB != Br->getSuccessor (0 ) );
17261723 SQ.CC = &CC;
17271724 CC.AffectedValues .insert (FuncArg);
17281725 Value *SimplifiedInstruction = llvm::simplifyInstructionWithOperands (
17291726 cast<CmpInst>(&Cmp), {CallArg, Cmp.getOperand (1 )}, SQ);
17301727 if (auto *ConstVal = dyn_cast_or_null<ConstantInt>(SimplifiedInstruction)) {
17311728 // Make sure that the BB of the recursive call is NOT the true successor
17321729 // of the icmp. In other words, make sure that the recursion depth is 1.
1733- if ((ConstVal->isOne () && ! CC.CondIsTrue ) ||
1734- (ConstVal->isZero () && CC.CondIsTrue )) {
1730+ if ((ConstVal->isOne () && CC.Invert ) ||
1731+ (ConstVal->isZero () && ! CC.Invert )) {
17351732 SimplifiedValues[&Cmp] = ConstVal;
17361733 return true ;
17371734 }
0 commit comments