@@ -153,7 +153,7 @@ class RecurrenceInstr;
153
153
class Rewriter {
154
154
protected:
155
155
MachineInstr &CopyLike;
156
- unsigned CurrentSrcIdx = 0 ; // /< The index of the source being rewritten.
156
+ int CurrentSrcIdx = 0 ; // /< The index of the source being rewritten.
157
157
public:
158
158
Rewriter (MachineInstr &CopyLike) : CopyLike(CopyLike) {}
159
159
virtual ~Rewriter () = default ;
@@ -201,12 +201,9 @@ class CopyRewriter : public Rewriter {
201
201
202
202
bool getNextRewritableSource (RegSubRegPair &Src,
203
203
RegSubRegPair &Dst) override {
204
- // CurrentSrcIdx > 0 means this function has already been called.
205
- if (CurrentSrcIdx > 0 )
204
+ if (CurrentSrcIdx++ > 1 )
206
205
return false ;
207
- // This is the first call to getNextRewritableSource.
208
- // Move the CurrentSrcIdx to remember that we made that call.
209
- CurrentSrcIdx = 1 ;
206
+
210
207
// The rewritable source is the argument.
211
208
const MachineOperand &MOSrc = CopyLike.getOperand (1 );
212
209
Src = RegSubRegPair (MOSrc.getReg (), MOSrc.getSubReg ());
@@ -217,8 +214,6 @@ class CopyRewriter : public Rewriter {
217
214
}
218
215
219
216
bool RewriteCurrentSource (Register NewReg, unsigned NewSubReg) override {
220
- if (CurrentSrcIdx != 1 )
221
- return false ;
222
217
MachineOperand &MOSrc = CopyLike.getOperand (CurrentSrcIdx);
223
218
MOSrc.setReg (NewReg);
224
219
MOSrc.setSubReg (NewSubReg);
@@ -229,7 +224,7 @@ class CopyRewriter : public Rewriter {
229
224
// / Helper class to rewrite uncoalescable copy like instructions
230
225
// / into new COPY (coalescable friendly) instructions.
231
226
class UncoalescableRewriter : public Rewriter {
232
- unsigned NumDefs; // /< Number of defs in the bitcast.
227
+ int NumDefs; // /< Number of defs in the bitcast.
233
228
234
229
public:
235
230
UncoalescableRewriter (MachineInstr &MI) : Rewriter(MI) {
@@ -383,6 +378,7 @@ class RegSequenceRewriter : public Rewriter {
383
378
public:
384
379
RegSequenceRewriter (MachineInstr &MI) : Rewriter(MI) {
385
380
assert (MI.isRegSequence () && " Invalid instruction" );
381
+ CurrentSrcIdx = -1 ;
386
382
}
387
383
388
384
// / \see Rewriter::getNextRewritableSource()
@@ -404,16 +400,10 @@ class RegSequenceRewriter : public Rewriter {
404
400
bool getNextRewritableSource (RegSubRegPair &Src,
405
401
RegSubRegPair &Dst) override {
406
402
// We are looking at v0 = REG_SEQUENCE v1, sub1, v2, sub2, etc.
403
+ CurrentSrcIdx += 2 ;
404
+ if (static_cast <unsigned >(CurrentSrcIdx) >= CopyLike.getNumOperands ())
405
+ return false ;
407
406
408
- // If this is the first call, move to the first argument.
409
- if (CurrentSrcIdx == 0 ) {
410
- CurrentSrcIdx = 1 ;
411
- } else {
412
- // Otherwise, move to the next argument and check that it is valid.
413
- CurrentSrcIdx += 2 ;
414
- if (CurrentSrcIdx >= CopyLike.getNumOperands ())
415
- return false ;
416
- }
417
407
const MachineOperand &MOInsertedReg = CopyLike.getOperand (CurrentSrcIdx);
418
408
Src.Reg = MOInsertedReg.getReg ();
419
409
// If we have to compose sub-register indices, bail out.
@@ -431,11 +421,6 @@ class RegSequenceRewriter : public Rewriter {
431
421
}
432
422
433
423
bool RewriteCurrentSource (Register NewReg, unsigned NewSubReg) override {
434
- // We cannot rewrite out of bound operands.
435
- // Moreover, rewritable sources are at odd positions.
436
- if ((CurrentSrcIdx & 1 ) != 1 || CurrentSrcIdx > CopyLike.getNumOperands ())
437
- return false ;
438
-
439
424
// Do not introduce new subregister uses in a reg_sequence. Until composing
440
425
// subregister indices is supported while folding, we're just blocking
441
426
// folding of subregister copies later in the function.
0 commit comments