Skip to content

Commit

Permalink
[DAG] visitSHL - move SimplifyDemandedBits after all standard folds t…
Browse files Browse the repository at this point in the history
…o give them a chance to match

Pulled out of D155472
  • Loading branch information
RKSimon committed Oct 2, 2023
1 parent f1fed12 commit b4f5913
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9857,9 +9857,6 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
return DAG.getNode(ISD::SHL, SDLoc(N), VT, N0, NewOp1);
}

if (SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);

// fold (shl (shl x, c1), c2) -> 0 or (shl x, (add c1, c2))
if (N0.getOpcode() == ISD::SHL) {
auto MatchOutOfRange = [OpSizeInBits](ConstantSDNode *LHS,
Expand Down Expand Up @@ -10077,6 +10074,9 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
if (SDValue NewSHL = visitShiftByConstant(N))
return NewSHL;

if (SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);

// Fold (shl (vscale * C0), C1) to (vscale * (C0 << C1)).
if (N0.getOpcode() == ISD::VSCALE && N1C) {
const APInt &C0 = N0.getConstantOperandAPInt(0);
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/AArch64/ushl_sat.ll
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ define i16 @combine_shlsat_to_shl(i16 %x) nounwind {
define i16 @combine_shlsat_to_shl_no_fold(i16 %x) nounwind {
; CHECK-LABEL: combine_shlsat_to_shl_no_fold:
; CHECK: // %bb.0:
; CHECK-NEXT: and w8, w0, #0xfffc
; CHECK-NEXT: lsl w9, w8, #17
; CHECK-NEXT: lsl w8, w8, #14
; CHECK-NEXT: lsl w8, w0, #14
; CHECK-NEXT: and w8, w8, #0x3fff0000
; CHECK-NEXT: lsl w9, w8, #3
; CHECK-NEXT: cmp w8, w9, lsr #3
; CHECK-NEXT: csinv w8, w9, wzr, eq
; CHECK-NEXT: lsr w0, w8, #16
Expand Down

0 comments on commit b4f5913

Please sign in to comment.