Skip to content

Commit 1a314b2

Browse files
committed
PeepholeOpt: Fix copy current source index accounting bug
We were essentially using the current source index as a binary value, and didn't actually use it for indexing so it did not matter. Use the operand to ensure the value is actually correct.
1 parent 85d4175 commit 1a314b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/CodeGen/PeepholeOptimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ class CopyRewriter : public Rewriter {
201201

202202
bool getNextRewritableSource(RegSubRegPair &Src,
203203
RegSubRegPair &Dst) override {
204-
if (CurrentSrcIdx++ > 1)
204+
if (++CurrentSrcIdx > 1)
205205
return false;
206206

207207
// The rewritable source is the argument.
208-
const MachineOperand &MOSrc = CopyLike.getOperand(1);
208+
const MachineOperand &MOSrc = CopyLike.getOperand(CurrentSrcIdx);
209209
Src = RegSubRegPair(MOSrc.getReg(), MOSrc.getSubReg());
210210
// What we track are the alternative sources of the definition.
211211
const MachineOperand &MODef = CopyLike.getOperand(0);

0 commit comments

Comments
 (0)