From f4145ddf5bedb1b87574f37df56be691ab554abd Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Fri, 1 Jul 2022 09:27:30 -0700 Subject: [PATCH] [GISel] Don't fold convergent instruction across CFG Before merging two instructions together, GISel does some sanity checks that the folding is legal. However that check was missing that the source of the pattern may be convergent. When the destination location is in a different basic block, the folding is invalid. Differential Revision: https://reviews.llvm.org/D128539 --- llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp index 3cd1b9ebeec4..8959d215ecd1 100644 --- a/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp @@ -59,6 +59,10 @@ bool InstructionSelector::isObviouslySafeToFold(MachineInstr &MI, std::next(MI.getIterator()) == IntoMI.getIterator()) return true; + // Convergent instructions cannot be moved in the CFG. + if (MI.isConvergent() && MI.getParent() != IntoMI.getParent()) + return false; + return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() && !MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty(); }