[PATCH] D129511: [SelectionDAG] Simplify how we drop poison flags in SimplifyDemandedBits.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 12:37:32 PDT 2022


craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon, efriedma, arsenm.
Herald added subscribers: StephenFan, ecnelises, steven.zhang, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

As far as I can tell what was happening in the original code is
that the getNode call receives the same operands as the original
node with different SDNodeFlags. The logic inside getNode detects
that the node already exists and intersects the flags into the
existing node and returns it. This results in Op and NewOp for the
TLO.CombineTo call always being the same node.

We may have already called CombineTo as part of the recursive handling.
A second call to CombineTo as we unwind the recursion overwrites
the previous CombineTo. I think this means any time we updated the
poison flags that was the only change that ends up getting made
and we relied on DAGCombiner to revisit and call SimplifyDemandedBits
again. The second time the poison flags wouldn't need to be dropped
and we would keep the CombineTo call from further down the recursion.

If this is all correct, I think we can get away with calling setFlags
(or intersectFlagsWith) to drop the flags and remove the call to
TLO.CombineTo. This way we keep the CombineTo from deeper in the
recursion which should be more efficient.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129511

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp


Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2509,9 +2509,7 @@
         // won't wrap after simplification.
         Flags.setNoSignedWrap(false);
         Flags.setNoUnsignedWrap(false);
-        SDValue NewOp =
-            TLO.DAG.getNode(Op.getOpcode(), dl, VT, Op0, Op1, Flags);
-        return TLO.CombineTo(Op, NewOp);
+        Op->setFlags(Flags);
       }
       return true;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129511.443720.patch
Type: text/x-patch
Size: 581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220711/da55be92/attachment.bin>


More information about the llvm-commits mailing list