Skip to content

Commit bdcd7c0

Browse files
authored
[DAGCombiner][RISCV] Preserve disjoint flag in folding (shl (or x, c1), c2) -> (or (shl x, c2), c1 << c2) (#76860)
Since we are shifting both inputs to the original Or by the same amount and inserting zeros in the LSBs, the result should still be disjoint.
1 parent a24c581 commit bdcd7c0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10055,7 +10055,11 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
1005510055
DAG.FoldConstantArithmetic(ISD::SHL, SDLoc(N1), VT, {N01, N1})) {
1005610056
SDValue Shl0 = DAG.getNode(ISD::SHL, SDLoc(N0), VT, N0.getOperand(0), N1);
1005710057
AddToWorklist(Shl0.getNode());
10058-
return DAG.getNode(N0.getOpcode(), SDLoc(N), VT, Shl0, Shl1);
10058+
SDNodeFlags Flags;
10059+
// Preserve the disjoint flag for Or.
10060+
if (N0.getOpcode() == ISD::OR && N0->getFlags().hasDisjoint())
10061+
Flags.setDisjoint(true);
10062+
return DAG.getNode(N0.getOpcode(), SDLoc(N), VT, Shl0, Shl1, Flags);
1005910063
}
1006010064
}
1006110065

llvm/test/CodeGen/RISCV/mem.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ define i32 @disjoint_or_lw(ptr %a, i32 %off) nounwind {
355355
; RV32I-LABEL: disjoint_or_lw:
356356
; RV32I: # %bb.0:
357357
; RV32I-NEXT: slli a1, a1, 2
358-
; RV32I-NEXT: ori a1, a1, 12
359358
; RV32I-NEXT: add a0, a0, a1
360-
; RV32I-NEXT: lw a0, 0(a0)
359+
; RV32I-NEXT: lw a0, 12(a0)
361360
; RV32I-NEXT: ret
362361
%b = or disjoint i32 %off, 3
363362
%1 = getelementptr i32, ptr %a, i32 %b

0 commit comments

Comments
 (0)