[llvm] 52c1162 - [RISCV][VLOPT] Clear DemandedVLs for each invocation of runOnMachineFunction

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 10:11:34 PST 2025


Author: Alex Bradbury
Date: 2025-02-02T18:05:13Z
New Revision: 52c116218b61c088ac77f26c7b57347a5f54224d

URL: https://github.com/llvm/llvm-project/commit/52c116218b61c088ac77f26c7b57347a5f54224d
DIFF: https://github.com/llvm/llvm-project/commit/52c116218b61c088ac77f26c7b57347a5f54224d.diff

LOG: [RISCV][VLOPT] Clear DemandedVLs for each invocation of runOnMachineFunction

I was running into failed assertions of `isCandidate(UserMI)` in
`getMinimumVLForUser`, but only occurring with
`-enable-machine-outliner=never`. I believe this is a red herring, and
it just so happens the memory allocation pattern on my machine exposed
the bug with that flag.

DemandedVLs is never cleared, which means it accumulates more
MachineInstr pointer keys over time, and it's possible that when e.g.
running on function 'b', a MachineInstr pointer points to the same
memory location used for a candidate in 'a'. This causes the assertion
to fail.

Comment left on #124530 with more information.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
index 4516d662bc779f9..0960245b8362d86 100644
--- a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
@@ -1334,6 +1334,7 @@ bool RISCVVLOptimizer::tryReduceVL(MachineInstr &MI) {
 }
 
 bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
+  assert(DemandedVLs.size() == 0);
   if (skipFunction(MF.getFunction()))
     return false;
 
@@ -1372,5 +1373,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
     }
   }
 
+  DemandedVLs.clear();
   return MadeChange;
 }


        


More information about the llvm-commits mailing list