[PATCH] D151945: Introduce G_OPAQUE and use it to prevent constant folding hoisted constants.

Amara Emerson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 5 09:19:52 PDT 2023


aemerson added inline comments.


================
Comment at: llvm/docs/GlobalISel/GenericOpcode.rst:945
+
+This operation is used as an opaque barrier to prevent constant folding. Combines
+and other transformations should not look through G_OPAQUE. These have no other
----------------
Pierre-vh wrote:
> I would generalize this to "prevent optimizations such as constant folding, sinking, or other combines."
That's fine, but should make it clear that this is an optimization barrier only for constants, not all operations. We shouldn't make the semantics too strong such that we struggle to enforce it.


================
Comment at: llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp:170-171
+      // Eliminate hints or G_OPAQUE.
+      if (isPreISelGenericOptimizationHint(MI.getOpcode()) ||
+          MI.getOpcode() == TargetOpcode::G_OPAQUE) {
+        auto [DstReg, SrcReg] = MI.getFirst2Regs();
----------------
Pierre-vh wrote:
> Could `G_OPAQUE` go in `isPreISelGenericOptimizationHint` as it's also some kind of optimization hint (barrier)?
I initially thought that, but `isPreISelGenericOptimizationHint()` is used as a means to look through copy-like instructions in `getDefSrcRegIgnoringCopies()` so that would be the opposite of what we want.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151945/new/

https://reviews.llvm.org/D151945



More information about the llvm-commits mailing list