@@ -263,8 +263,6 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
263
263
// Cache the DataLayout since we use it a lot.
264
264
const DataLayout &DL;
265
265
266
- DominatorTree DT;
267
-
268
266
// / The OptimizationRemarkEmitter available for this compilation.
269
267
OptimizationRemarkEmitter *ORE;
270
268
@@ -1691,9 +1689,8 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
1691
1689
// Make sure that the callsite is recursive:
1692
1690
if (CandidateCall.getCaller () != &F)
1693
1691
return false ;
1694
- CallInst *CallInstr = dyn_cast<CallInst>(&CandidateCall);
1695
1692
// Only handle the case when the callsite has a single predecessor:
1696
- auto *CallBB = CallInstr-> getParent ();
1693
+ auto *CallBB = CandidateCall. getParent ();
1697
1694
auto *Predecessor = CallBB->getSinglePredecessor ();
1698
1695
if (!Predecessor)
1699
1696
return false ;
@@ -1707,9 +1704,9 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
1707
1704
bool ArgFound = false ;
1708
1705
Value *FuncArg = nullptr , *CallArg = nullptr ;
1709
1706
for (unsigned ArgNum = 0 ;
1710
- ArgNum < F.arg_size () && ArgNum < CallInstr-> arg_size (); ArgNum++) {
1707
+ ArgNum < F.arg_size () && ArgNum < CandidateCall. arg_size (); ArgNum++) {
1711
1708
FuncArg = F.getArg (ArgNum);
1712
- CallArg = CallInstr-> getArgOperand (ArgNum);
1709
+ CallArg = CandidateCall. getArgOperand (ArgNum);
1713
1710
if (FuncArg == CmpOp && CallArg != CmpOp) {
1714
1711
ArgFound = true ;
1715
1712
break ;
@@ -1721,17 +1718,17 @@ bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
1721
1718
// Now we have a recursive call that is guarded by a cmp instruction.
1722
1719
// Check if this cmp can be simplified:
1723
1720
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 ) );
1726
1723
SQ.CC = &CC;
1727
1724
CC.AffectedValues .insert (FuncArg);
1728
1725
Value *SimplifiedInstruction = llvm::simplifyInstructionWithOperands (
1729
1726
cast<CmpInst>(&Cmp), {CallArg, Cmp.getOperand (1 )}, SQ);
1730
1727
if (auto *ConstVal = dyn_cast_or_null<ConstantInt>(SimplifiedInstruction)) {
1731
1728
// Make sure that the BB of the recursive call is NOT the true successor
1732
1729
// 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 )) {
1735
1732
SimplifiedValues[&Cmp] = ConstVal;
1736
1733
return true ;
1737
1734
}
0 commit comments