[llvm] [DAG] Remove OneUse restriction when folding (shl (add x, c1), c2) (PR #101294)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 02:42:50 PDT 2024
================
@@ -10070,17 +10070,33 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
// Variant of version done on multiply, except mul by a power of 2 is turned
// into a shift.
if ((N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::OR) &&
- N0->hasOneUse() && TLI.isDesirableToCommuteWithShift(N, Level)) {
- SDValue N01 = N0.getOperand(1);
- if (SDValue Shl1 =
- DAG.FoldConstantArithmetic(ISD::SHL, SDLoc(N1), VT, {N01, N1})) {
- SDValue Shl0 = DAG.getNode(ISD::SHL, SDLoc(N0), VT, N0.getOperand(0), N1);
- AddToWorklist(Shl0.getNode());
- SDNodeFlags Flags;
- // Preserve the disjoint flag for Or.
- if (N0.getOpcode() == ISD::OR && N0->getFlags().hasDisjoint())
- Flags.setDisjoint(true);
- return DAG.getNode(N0.getOpcode(), DL, VT, Shl0, Shl1, Flags);
+ TLI.isDesirableToCommuteWithShift(N, Level)) {
+ // LD/ST will optimize constant Offset extraction, so when AddNode
+ // is used by LD/ST, it can still complete the folding optimization
+ // operation performed above.
----------------
LiqinWeng wrote:
![image](https://github.com/user-attachments/assets/a7b17f20-045e-463c-8d32-a5bb5abda7b4)
If I must do this optimization, where do you think it would be better to do it?
https://github.com/llvm/llvm-project/pull/101294
More information about the llvm-commits
mailing list