@@ -59,7 +59,7 @@ struct UpliftWhileOp : public OpRewritePattern<scf::WhileOp> {
59
59
diag << " Expected 'slt' or 'sgt' predicate: " << *cmp;
60
60
});
61
61
62
- BlockArgument indVar ;
62
+ BlockArgument inductionVar ;
63
63
Value ub;
64
64
DominanceInfo dom;
65
65
@@ -81,46 +81,47 @@ struct UpliftWhileOp : public OpRewritePattern<scf::WhileOp> {
81
81
if (!dom.properlyDominates (arg2, loop))
82
82
continue ;
83
83
84
- indVar = blockArg;
84
+ inductionVar = blockArg;
85
85
ub = arg2;
86
86
break ;
87
87
}
88
88
89
- if (!indVar )
89
+ if (!inductionVar )
90
90
return rewriter.notifyMatchFailure (loop, [&](Diagnostic &diag) {
91
91
diag << " Unrecognized cmp form: " << *cmp;
92
92
});
93
93
94
- // indVar must have 2 uses: one is in `cmp` and other is `condition` arg.
95
- if (!llvm::hasNItems (indVar.getUses (), 2 ))
94
+ // inductionVar must have 2 uses: one is in `cmp` and other is `condition`
95
+ // arg.
96
+ if (!llvm::hasNItems (inductionVar.getUses (), 2 ))
96
97
return rewriter.notifyMatchFailure (loop, [&](Diagnostic &diag) {
97
- diag << " Unrecognized induction var: " << indVar ;
98
+ diag << " Unrecognized induction var: " << inductionVar ;
98
99
});
99
100
100
101
Block *afterBody = loop.getAfterBody ();
101
102
scf::YieldOp afterTerm = loop.getYieldOp ();
102
- auto argNumber = indVar .getArgNumber ();
103
- auto afterTermIterArg = afterTerm.getResults ()[argNumber];
103
+ auto argNumber = inductionVar .getArgNumber ();
104
+ auto afterTermIndArg = afterTerm.getResults ()[argNumber];
104
105
105
- auto indVarAfter = afterBody->getArgument (argNumber);
106
+ auto inductionVarAfter = afterBody->getArgument (argNumber);
106
107
107
108
Value step;
108
109
109
110
// Find suitable `addi` op inside `after` block, one of the args must be an
110
111
// Induction var passed from `before` block and second arg must be defined
111
112
// outside of the loop and will be considered step value.
112
113
// TODO: Add `subi` support?
113
- for (auto &use : indVarAfter .getUses ()) {
114
+ for (auto &use : inductionVarAfter .getUses ()) {
114
115
auto owner = dyn_cast<arith::AddIOp>(use.getOwner ());
115
116
if (!owner)
116
117
continue ;
117
118
118
- auto other =
119
- (indVarAfter == owner. getLhs () ? owner. getRhs () : owner.getLhs ());
119
+ auto other = (inductionVarAfter == owner. getLhs () ? owner. getRhs ()
120
+ : owner.getLhs ());
120
121
if (!dom.properlyDominates (other, loop))
121
122
continue ;
122
123
123
- if (afterTermIterArg != owner.getResult ())
124
+ if (afterTermIndArg != owner.getResult ())
124
125
continue ;
125
126
126
127
step = other;
@@ -139,7 +140,7 @@ struct UpliftWhileOp : public OpRewritePattern<scf::WhileOp> {
139
140
140
141
llvm::SmallVector<Value> newArgs;
141
142
142
- // Populate inits for new `scf.for`
143
+ // Populate inits for new `scf.for`, skip induction var.
143
144
newArgs.reserve (loop.getInits ().size ());
144
145
for (auto &&[i, init] : llvm::enumerate (loop.getInits ())) {
145
146
if (i == argNumber)
0 commit comments