Skip to content

Commit b4f5913

Browse files
committed
[DAG] visitSHL - move SimplifyDemandedBits after all standard folds to give them a chance to match
Pulled out of D155472
1 parent f1fed12 commit b4f5913

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9857,9 +9857,6 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
98579857
return DAG.getNode(ISD::SHL, SDLoc(N), VT, N0, NewOp1);
98589858
}
98599859

9860-
if (SimplifyDemandedBits(SDValue(N, 0)))
9861-
return SDValue(N, 0);
9862-
98639860
// fold (shl (shl x, c1), c2) -> 0 or (shl x, (add c1, c2))
98649861
if (N0.getOpcode() == ISD::SHL) {
98659862
auto MatchOutOfRange = [OpSizeInBits](ConstantSDNode *LHS,
@@ -10077,6 +10074,9 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
1007710074
if (SDValue NewSHL = visitShiftByConstant(N))
1007810075
return NewSHL;
1007910076

10077+
if (SimplifyDemandedBits(SDValue(N, 0)))
10078+
return SDValue(N, 0);
10079+
1008010080
// Fold (shl (vscale * C0), C1) to (vscale * (C0 << C1)).
1008110081
if (N0.getOpcode() == ISD::VSCALE && N1C) {
1008210082
const APInt &C0 = N0.getConstantOperandAPInt(0);

llvm/test/CodeGen/AArch64/ushl_sat.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ define i16 @combine_shlsat_to_shl(i16 %x) nounwind {
128128
define i16 @combine_shlsat_to_shl_no_fold(i16 %x) nounwind {
129129
; CHECK-LABEL: combine_shlsat_to_shl_no_fold:
130130
; CHECK: // %bb.0:
131-
; CHECK-NEXT: and w8, w0, #0xfffc
132-
; CHECK-NEXT: lsl w9, w8, #17
133-
; CHECK-NEXT: lsl w8, w8, #14
131+
; CHECK-NEXT: lsl w8, w0, #14
132+
; CHECK-NEXT: and w8, w8, #0x3fff0000
133+
; CHECK-NEXT: lsl w9, w8, #3
134134
; CHECK-NEXT: cmp w8, w9, lsr #3
135135
; CHECK-NEXT: csinv w8, w9, wzr, eq
136136
; CHECK-NEXT: lsr w0, w8, #16

0 commit comments

Comments
 (0)