Skip to content

Commit ef5deba

Browse files
committed
[SelectionDAG] ComputeKnownBits add getValidMinimumShiftAmountConstant() ISD::SHL support
As mentioned on D72573
1 parent 7efc7ca commit ef5deba

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,9 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
28342834
Known.One <<= Shift;
28352835
// Low bits are known zero.
28362836
Known.Zero.setLowBits(Shift);
2837+
} else if (const APInt *ShMinAmt = getValidMinimumShiftAmountConstant(Op)) {
2838+
// Minimum shift low bits are known zero.
2839+
Known.Zero.setLowBits(ShMinAmt->getZExtValue());
28372840
} else {
28382841
// No matter the shift amount, the trailing zeros will stay zero.
28392842
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);

llvm/test/CodeGen/X86/combine-shl.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ define <4 x i32> @combine_vec_shl_mul1(<4 x i32> %x) {
834834
}
835835

836836
; fold (add (shl x, c1), c2) -> (or (shl x, c1), c2)
837-
; TODO: Handle minimum shift value case
838837
define <4 x i32> @combine_vec_add_shl_nonsplat(<4 x i32> %a0) {
839838
; SSE2-LABEL: combine_vec_add_shl_nonsplat:
840839
; SSE2: # %bb.0:
@@ -846,7 +845,7 @@ define <4 x i32> @combine_vec_add_shl_nonsplat(<4 x i32> %a0) {
846845
; SSE2-NEXT: pmuludq %xmm2, %xmm1
847846
; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
848847
; SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
849-
; SSE2-NEXT: paddd {{.*}}(%rip), %xmm0
848+
; SSE2-NEXT: por {{.*}}(%rip), %xmm0
850849
; SSE2-NEXT: retq
851850
;
852851
; SSE41-LABEL: combine_vec_add_shl_nonsplat:
@@ -859,7 +858,7 @@ define <4 x i32> @combine_vec_add_shl_nonsplat(<4 x i32> %a0) {
859858
; AVX: # %bb.0:
860859
; AVX-NEXT: vpsllvd {{.*}}(%rip), %xmm0, %xmm0
861860
; AVX-NEXT: vpbroadcastd {{.*#+}} xmm1 = [3,3,3,3]
862-
; AVX-NEXT: vpaddd %xmm1, %xmm0, %xmm0
861+
; AVX-NEXT: vpor %xmm1, %xmm0, %xmm0
863862
; AVX-NEXT: retq
864863
%1 = shl <4 x i32> %a0, <i32 2, i32 3, i32 4, i32 5>
865864
%2 = add <4 x i32> %1, <i32 3, i32 3, i32 3, i32 3>

0 commit comments

Comments
 (0)