[llvm] 1a314b2 - PeepholeOpt: Fix copy current source index accounting bug

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 06:17:36 PST 2025


Author: Matt Arsenault
Date: 2025-01-31T21:17:20+07:00
New Revision: 1a314b2472a834466e728533ac8b540b1d0d9304

URL: https://github.com/llvm/llvm-project/commit/1a314b2472a834466e728533ac8b540b1d0d9304
DIFF: https://github.com/llvm/llvm-project/commit/1a314b2472a834466e728533ac8b540b1d0d9304.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/PeepholeOptimizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index a8a40cdb915ed5..d93600265da0ab 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -201,11 +201,11 @@ class CopyRewriter : public Rewriter {
 
   bool getNextRewritableSource(RegSubRegPair &Src,
                                RegSubRegPair &Dst) override {
-    if (CurrentSrcIdx++ > 1)
+    if (++CurrentSrcIdx > 1)
       return false;
 
     // The rewritable source is the argument.
-    const MachineOperand &MOSrc = CopyLike.getOperand(1);
+    const MachineOperand &MOSrc = CopyLike.getOperand(CurrentSrcIdx);
     Src = RegSubRegPair(MOSrc.getReg(), MOSrc.getSubReg());
     // What we track are the alternative sources of the definition.
     const MachineOperand &MODef = CopyLike.getOperand(0);


        


More information about the llvm-commits mailing list