Skip to content

Commit 262994c

Browse files
committed
comments
1 parent 51fa20d commit 262994c

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
@@ -28992,7 +28992,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2899228992

2899328993
EVT VT = Root.getValueType();
2899428994

28995-
if (Root.getOpcode() != ISD::AND)
28995+
if (!VT.isScalarInteger() || Root.getOpcode() != ISD::AND)
2899628996
return SDValue();
2899728997

2899828998
SDValue N0 = Root.getOperand(0);
@@ -29002,8 +29002,6 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2900229002
return SDValue();
2900329003

2900429004
APInt RootMask = cast<ConstantSDNode>(N1)->getAsAPIntVal();
29005-
if (!RootMask.isMask())
29006-
return SDValue();
2900729005

2900829006
SDValue Src;
2900929007
const auto IsSrc = [&](SDValue V) {
@@ -29019,7 +29017,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2901929017
APInt PartsMask(VT.getSizeInBits(), 0);
2902029018
while (!Worklist.empty()) {
2902129019
SDValue V = Worklist.pop_back_val();
29022-
if (!V.hasOneUse() && Src != V)
29020+
if (!V.hasOneUse() && (Src && Src != V))
2902329021
return SDValue();
2902429022

2902529023
if (V.getOpcode() == ISD::OR) {
@@ -29035,7 +29033,11 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2903529033
if (!IsSrc(ShiftSrc) || !isa<ConstantSDNode>(ShiftAmt))
2903629034
return SDValue();
2903729035

29038-
PartsMask |= (RootMask << cast<ConstantSDNode>(ShiftAmt)->getAsZExtVal());
29036+
auto ShiftAmtVal = cast<ConstantSDNode>(ShiftAmt)->getAsZExtVal();
29037+
if (ShiftAmtVal > RootMask.getBitWidth())
29038+
return SDValue();
29039+
29040+
PartsMask |= (RootMask << ShiftAmtVal);
2903929041
continue;
2904029042
}
2904129043

@@ -29047,7 +29049,7 @@ static SDValue matchMergedBFX(SDValue Root, SelectionDAG &DAG,
2904729049
return SDValue();
2904829050
}
2904929051

29050-
if (!RootMask.isMask() || !Src)
29052+
if (!Src)
2905129053
return SDValue();
2905229054

2905329055
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)