Skip to content

Commit

Permalink
[DAGCombiner][RISCV] Preserve disjoint flag in folding (shl (or x, c1…
Browse files Browse the repository at this point in the history
…), 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.
  • Loading branch information
topperc committed Jan 3, 2024
1 parent a24c581 commit bdcd7c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10055,7 +10055,11 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
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());
return DAG.getNode(N0.getOpcode(), SDLoc(N), VT, Shl0, Shl1);
SDNodeFlags Flags;
// Preserve the disjoint flag for Or.
if (N0.getOpcode() == ISD::OR && N0->getFlags().hasDisjoint())
Flags.setDisjoint(true);
return DAG.getNode(N0.getOpcode(), SDLoc(N), VT, Shl0, Shl1, Flags);
}
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/RISCV/mem.ll
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,8 @@ define i32 @disjoint_or_lw(ptr %a, i32 %off) nounwind {
; RV32I-LABEL: disjoint_or_lw:
; RV32I: # %bb.0:
; RV32I-NEXT: slli a1, a1, 2
; RV32I-NEXT: ori a1, a1, 12
; RV32I-NEXT: add a0, a0, a1
; RV32I-NEXT: lw a0, 0(a0)
; RV32I-NEXT: lw a0, 12(a0)
; RV32I-NEXT: ret
%b = or disjoint i32 %off, 3
%1 = getelementptr i32, ptr %a, i32 %b
Expand Down

0 comments on commit bdcd7c0

Please sign in to comment.