[llvm] f4145dd - [GISel] Don't fold convergent instruction across CFG

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 1 10:24:29 PDT 2022


Author: Quentin Colombet
Date: 2022-07-01T10:24:24-07:00
New Revision: f4145ddf5bedb1b87574f37df56be691ab554abd

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

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelector.cpp
index 3cd1b9ebeec4d..8959d215ecd1a 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();
 }


        


More information about the llvm-commits mailing list