Skip to content

Commit a3ee9d6

Browse files
committed
comments
1 parent 2661513 commit a3ee9d6

File tree

2 files changed

+110
-6
lines changed

2 files changed

+110
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28922,7 +28922,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2892228922

2892328923
EVT VT = Root.getValueType();
2892428924

28925-
if (Root.getOpcode() != ISD::AND)
28925+
if (!VT.isScalarInteger() || Root.getOpcode() != ISD::AND)
2892628926
return SDValue();
2892728927

2892828928
SDValue N0 = Root.getOperand(0);
@@ -28932,8 +28932,6 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2893228932
return SDValue();
2893328933

2893428934
APInt RootMask = cast<ConstantSDNode>(N1)->getAsAPIntVal();
28935-
if (!RootMask.isMask())
28936-
return SDValue();
2893728935

2893828936
SDValue Src;
2893928937
const auto IsSrc = [&](SDValue V) {
@@ -28949,7 +28947,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2894928947
APInt PartsMask(VT.getSizeInBits(), 0);
2895028948
while (!Worklist.empty()) {
2895128949
SDValue V = Worklist.pop_back_val();
28952-
if (!V.hasOneUse() && Src != V)
28950+
if (!V.hasOneUse() && (Src && Src != V))
2895328951
return SDValue();
2895428952

2895528953
if (V.getOpcode() == ISD::OR) {
@@ -28965,7 +28963,11 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2896528963
if (!IsSrc(ShiftSrc) || !isa<ConstantSDNode>(ShiftAmt))
2896628964
return SDValue();
2896728965

28968-
PartsMask |= (RootMask << cast<ConstantSDNode>(ShiftAmt)->getAsZExtVal());
28966+
auto ShiftAmtVal = cast<ConstantSDNode>(ShiftAmt)->getAsZExtVal();
28967+
if (ShiftAmtVal > RootMask.getBitWidth())
28968+
return SDValue();
28969+
28970+
PartsMask |= (RootMask << ShiftAmtVal);
2896928971
continue;
2897028972
}
2897128973

@@ -28977,7 +28979,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2897728979
return SDValue();
2897828980
}
2897928981

28980-
if (!RootMask.isMask() || !Src)
28982+
if (!Src)
2898128983
return SDValue();
2898228984

2898328985
SDLoc DL(Root);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -O3 -mtriple=amdgcn -mcpu=fiji %s -o - | FileCheck %s
3+
4+
define i1 @basic_eq_i16_3x5(i16 %arg) {
5+
; CHECK-LABEL: basic_eq_i16_3x5:
6+
; CHECK: ; %bb.0: ; %entry
7+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8+
; CHECK-NEXT: v_and_b32_e32 v0, 0x7fff, v0
9+
; CHECK-NEXT: v_cmp_eq_u16_e32 vcc, 0, v0
10+
; CHECK-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
11+
; CHECK-NEXT: s_setpc_b64 s[30:31]
12+
entry:
13+
%a = and i16 %arg, 31
14+
%sh5 = lshr i16 %arg, 5
15+
%b = and i16 %sh5, 31
16+
%or = or i16 %a, %b
17+
%sh10 = lshr i16 %arg, 10
18+
%c = and i16 %sh10, 31
19+
%or1 = or i16 %or, %c
20+
%cmp = icmp eq i16 %or1, 0
21+
ret i1 %cmp
22+
}
23+
24+
define i1 @basic_eq_i32_3x5(i32 %arg) {
25+
; CHECK-LABEL: basic_eq_i32_3x5:
26+
; CHECK: ; %bb.0: ; %entry
27+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
28+
; CHECK-NEXT: v_and_b32_e32 v0, 0x7fff, v0
29+
; CHECK-NEXT: v_cmp_eq_u32_e32 vcc, 0, v0
30+
; CHECK-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
31+
; CHECK-NEXT: s_setpc_b64 s[30:31]
32+
entry:
33+
%a = and i32 %arg, 31
34+
%sh5 = lshr i32 %arg, 5
35+
%b = and i32 %sh5, 31
36+
%or = or i32 %a, %b
37+
%sh10 = lshr i32 %arg, 10
38+
%c = and i32 %sh10, 31
39+
%or1 = or i32 %or, %c
40+
%cmp = icmp eq i32 %or1, 0
41+
ret i1 %cmp
42+
}
43+
44+
define i1 @basic_eq_i64_3x5(i64 %arg) {
45+
; CHECK-LABEL: basic_eq_i64_3x5:
46+
; CHECK: ; %bb.0: ; %entry
47+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
48+
; CHECK-NEXT: v_and_b32_e32 v0, 0x7fff, v0
49+
; CHECK-NEXT: v_cmp_eq_u32_e32 vcc, 0, v0
50+
; CHECK-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
51+
; CHECK-NEXT: s_setpc_b64 s[30:31]
52+
entry:
53+
%a = and i64 %arg, 31
54+
%sh5 = lshr i64 %arg, 5
55+
%b = and i64 %sh5, 31
56+
%or = or i64 %a, %b
57+
%sh10 = lshr i64 %arg, 10
58+
%c = and i64 %sh10, 31
59+
%or1 = or i64 %or, %c
60+
%cmp = icmp eq i64 %or1, 0
61+
ret i1 %cmp
62+
}
63+
64+
define i1 @basic_ne_i32_3x5(i32 %arg) {
65+
; CHECK-LABEL: basic_ne_i32_3x5:
66+
; CHECK: ; %bb.0: ; %entry
67+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
68+
; CHECK-NEXT: v_and_b32_e32 v0, 0x7fff, v0
69+
; CHECK-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
70+
; CHECK-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
71+
; CHECK-NEXT: s_setpc_b64 s[30:31]
72+
entry:
73+
%a = and i32 %arg, 31
74+
%sh5 = lshr i32 %arg, 5
75+
%b = and i32 %sh5, 31
76+
%or = or i32 %a, %b
77+
%sh10 = lshr i32 %arg, 10
78+
%c = and i32 %sh10, 31
79+
%or1 = or i32 %or, %c
80+
%cmp = icmp ne i32 %or1, 0
81+
ret i1 %cmp
82+
}
83+
84+
define i1 @eq_i32_3x5_holes_in_mask(i32 %arg) {
85+
; CHECK-LABEL: eq_i32_3x5_holes_in_mask:
86+
; CHECK: ; %bb.0: ; %entry
87+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
88+
; CHECK-NEXT: v_and_b32_e32 v0, 0x7f9f, v0
89+
; CHECK-NEXT: v_cmp_ne_u32_e32 vcc, 0, v0
90+
; CHECK-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
91+
; CHECK-NEXT: s_setpc_b64 s[30:31]
92+
entry:
93+
%a = and i32 %arg, 31
94+
%sh5 = lshr i32 %arg, 7
95+
%b = and i32 %sh5, 31
96+
%or = or i32 %a, %b
97+
%sh10 = lshr i32 %arg, 10
98+
%c = and i32 %sh10, 31
99+
%or1 = or i32 %or, %c
100+
%cmp = icmp ne i32 %or1, 0
101+
ret i1 %cmp
102+
}

0 commit comments

Comments
 (0)