Skip to content

Commit 37559c8

Browse files
authored
[Hexagon] Handle Call Operand vxi1 in Hexagon Backend (#128027)
This commit updates the Hexagon backend to handle vxi1 call operands. It ensures compatibility for vector types of sizes 4, 8, 16, 32, 64, and 128 x i1 when HVX is enabled. ~Fixes #59009 and #118879~
1 parent a821ae2 commit 37559c8

File tree

7 files changed

+275
-0
lines changed

7 files changed

+275
-0
lines changed

llvm/lib/Target/Hexagon/HexagonCallingConv.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def CC_Hexagon: CallingConv<[
6565
CCIfType<[i32],
6666
CCIfSplit<
6767
CCCustom<"CC_SkipOdd">>>,
68+
CCIfType<[v4i1], CCPromoteToType<v4i16>>,
69+
CCIfType<[v8i1], CCPromoteToType<v8i8>>,
6870

6971
CCIfType<[i32,v2i16,v4i8],
7072
CCAssignToReg<[R0,R1,R2,R3,R4,R5]>>,
@@ -111,6 +113,14 @@ class CCIfHvx128<CCAction A>
111113

112114
def CC_Hexagon_HVX: CallingConv<[
113115
// HVX 64-byte mode
116+
117+
CCIfHvx64<
118+
CCIfType<[v16i1], CCPromoteToType<v16i32>>>,
119+
CCIfHvx64<
120+
CCIfType<[v32i1], CCPromoteToType<v32i16>>>,
121+
CCIfHvx64<
122+
CCIfType<[v64i1], CCPromoteToType<v64i8>>>,
123+
114124
CCIfHvx64<
115125
CCIfType<[v16i32,v32i16,v64i8],
116126
CCAssignToReg<[V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15]>>>,
@@ -125,6 +135,14 @@ def CC_Hexagon_HVX: CallingConv<[
125135
CCAssignToStack<128,64>>>,
126136

127137
// HVX 128-byte mode
138+
139+
CCIfHvx128<
140+
CCIfType<[v32i1], CCPromoteToType<v32i32>>>,
141+
CCIfHvx128<
142+
CCIfType<[v64i1], CCPromoteToType<v64i16>>>,
143+
CCIfHvx128<
144+
CCIfType<[v128i1], CCPromoteToType<v128i8>>>,
145+
128146
CCIfHvx128<
129147
CCIfType<[v32i32,v64i16,v128i8,v32f32,v64f16],
130148
CCAssignToReg<[V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15]>>>,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s
2+
3+
; CHECK-LABEL: compare_vectors
4+
; CHECK: [[REG1:(q[0-9]+)]] = vcmp.eq(v{{[0-9]+}}.b,v{{[0-9]+}}.b)
5+
; CHECK: [[REG2:(r[0-9]+)]] = #-1
6+
; CHECK: v0 = vand([[REG1]],[[REG2]])
7+
8+
define void @compare_vectors(<128 x i8> %a, <128 x i8> %b) {
9+
entry:
10+
%result = icmp eq <128 x i8> %a, %b
11+
call i32 @f.1(<128 x i1> %result)
12+
ret void
13+
}
14+
15+
; CHECK-LABEL: f.1:
16+
; CHECK: [[REG3:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
17+
; CHECK: [[REG4:(v[0-9]+)]] = vand([[REG3]],r{{[0-9]+}})
18+
; CHECK: r{{[0-9]+}} = vextract([[REG4]],r{{[0-9]+}})
19+
20+
define i32 @f.1(<128 x i1> %vec) {
21+
%element = extractelement <128 x i1> %vec, i32 6
22+
%is_true = icmp eq i1 %element, true
23+
br i1 %is_true, label %if_true, label %if_false
24+
25+
if_true:
26+
call void @action_if_true()
27+
br label %end
28+
29+
if_false:
30+
call void @action_if_false()
31+
br label %end
32+
33+
end:
34+
%result = phi i32 [1, %if_true], [0, %if_false]
35+
ret i32 %result
36+
}
37+
38+
declare void @action_if_true()
39+
declare void @action_if_false()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length64b < %s -o - | FileCheck %s --check-prefix=CHECK
2+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s --check-prefix=CHECK
3+
4+
; CHECK-LABEL: compare_vectors
5+
; CHECK: [[REG1:(q[0-9]+)]] = vcmp.eq(v{{[0-9]+}}.w,v{{[0-9]+}}.w)
6+
; CHECK: [[REG2:(r[0-9]+)]] = #-1
7+
; CHECK: v0 = vand([[REG1]],[[REG2]])
8+
9+
define void @compare_vectors(<16 x i32> %a, <16 x i32> %b) {
10+
entry:
11+
%result = icmp eq <16 x i32> %a, %b
12+
call i32 @f.1(<16 x i1> %result)
13+
ret void
14+
}
15+
16+
; CHECK-LABEL: f.1:
17+
; CHECK: [[REG3:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
18+
; CHECK: [[REG4:(v[0-9]+)]] = vand([[REG3]],r{{[0-9]+}})
19+
; CHECK: r{{[0-9]+}} = vextract([[REG4]],r{{[0-9]+}})
20+
21+
define i32 @f.1(<16 x i1> %vec) {
22+
%element = extractelement <16 x i1> %vec, i32 6
23+
%is_true = icmp eq i1 %element, true
24+
br i1 %is_true, label %if_true, label %if_false
25+
26+
if_true:
27+
call void @action_if_true()
28+
br label %end
29+
30+
if_false:
31+
call void @action_if_false()
32+
br label %end
33+
34+
end:
35+
%result = phi i32 [1, %if_true], [0, %if_false]
36+
ret i32 %result
37+
}
38+
39+
declare void @action_if_true()
40+
declare void @action_if_false()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length64b < %s -o - | FileCheck %s --check-prefix=CHECK-64
2+
; RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s --check-prefix=CHECK-128
3+
4+
; CHECK-LABEL: compare_vectors
5+
; CHECK-64: [[REG1:(q[0-9]+)]] = vcmp.eq(v{{[0-9]+}}.h,v{{[0-9]+}}.h)
6+
; CHECK-64: [[REG2:(r[0-9]+)]] = #-1
7+
; CHECK-64: v0 = vand([[REG1]],[[REG2]])
8+
; CHECK-128: r{{[0-9]+}}:{{[0-9]+}} = combine(##.LCPI0_0,#-1)
9+
; CHECK-128: [[REG1:(q[0-9]+)]] = vcmp.eq(v0.h,v1.h)
10+
; CHECK-128: [[REG2:(v[0-9]+)]] = vand([[REG1]],r{{[0-9]+}})
11+
; CHECK-128: [[REG3:(v[0-9]+)]] = vmem(r{{[0-9]+}}+#0)
12+
; CHECK-128: [[REG4:(v[0-9]+)]] = vdelta([[REG2]],[[REG3]])
13+
; CHECK-128: [[REG5:(q[0-9]+)]] = vand([[REG4]],r{{[0-9]+}})
14+
; CHECK-128: v0 = vand([[REG5]],r{{[0-9]+}})
15+
16+
define void @compare_vectors(<32 x i16> %a, <32 x i16> %b) {
17+
entry:
18+
%result = icmp eq <32 x i16> %a, %b
19+
call i32 @f.1(<32 x i1> %result)
20+
ret void
21+
}
22+
23+
; CHECK-LABEL: f.1:
24+
; CHECK-64: [[REG3:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
25+
; CHECK-64: [[REG4:(v[0-9]+)]] = vand([[REG3]],r{{[0-9]+}})
26+
; CHECK-64: r{{[0-9]+}} = vextract([[REG4]],r{{[0-9]+}})
27+
; CHECK-128: [[REG6:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
28+
; CHECK-128: [[REG7:(v[0-9]+)]] = vand([[REG6]],r{{[0-9]+}})
29+
; CHECK-128: r{{[0-9]+}} = vextract([[REG7]],r{{[0-9]+}})
30+
31+
define i32 @f.1(<32 x i1> %vec) {
32+
%element = extractelement <32 x i1> %vec, i32 6
33+
%is_true = icmp eq i1 %element, true
34+
br i1 %is_true, label %if_true, label %if_false
35+
36+
if_true:
37+
call void @action_if_true()
38+
br label %end
39+
40+
if_false:
41+
call void @action_if_false()
42+
br label %end
43+
44+
end:
45+
%result = phi i32 [1, %if_true], [0, %if_false]
46+
ret i32 %result
47+
}
48+
49+
declare void @action_if_true()
50+
declare void @action_if_false()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;RUN: llc -mtriple=hexagon < %s -o - | FileCheck %s --check-prefix=CHECK
2+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length64b < %s -o - | FileCheck %s --check-prefix=CHECK
3+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s --check-prefix=CHECK
4+
5+
; CHECK-LABEL: compare_vectors
6+
; CHECK: [[REG0:(p[0-9]+)]] = vcmph.eq([[REG1:(r[0-9]+):[0-9]]],[[REG2:(r[0-9]+):[0-9]]])
7+
; CHECK: [[REG1:(r[0-9]+):[0-9]]] = CONST64(#281479271743489)
8+
; CHECK: [[REG2:(r[0-9]+):[0-9]]] = mask([[REG0]])
9+
; CHECK: r{{[0-9]+}}:{{[0-9]+}} = and([[REG2]],[[REG1]])
10+
11+
define void @compare_vectors(<4 x i16> %a, <4 x i16> %b) {
12+
entry:
13+
%result = icmp eq <4 x i16> %a, %b
14+
call i32 @f.1(<4 x i1> %result)
15+
ret void
16+
}
17+
; CHECK-LABEL: f.1:
18+
; CHECK: [[REG3:(r[0-9]+)]] = and([[REG3]],##65537)
19+
; CHECK: [[REG4:(r[0-9]+)]] = and([[REG4]],##65537)
20+
define i32 @f.1(<4 x i1> %vec) {
21+
%element = extractelement <4 x i1> %vec, i32 2
22+
%is_true = icmp eq i1 %element, true
23+
br i1 %is_true, label %if_true, label %if_false
24+
25+
if_true:
26+
call void @action_if_true()
27+
br label %end
28+
29+
if_false:
30+
call void @action_if_false()
31+
br label %end
32+
33+
end:
34+
%result = phi i32 [1, %if_true], [0, %if_false]
35+
ret i32 %result
36+
}
37+
38+
declare void @action_if_true()
39+
declare void @action_if_false()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length64b < %s -o - | FileCheck %s --check-prefix=CHECK-64
2+
; RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s --check-prefix=CHECK-128
3+
4+
; CHECK-LABEL: compare_vectors
5+
; CHECK-64: [[REG1:(q[0-9]+)]] = vcmp.eq(v{{[0-9]+}}.b,v{{[0-9]+}}.b)
6+
; CHECK-64: [[REG2:(r[0-9]+)]] = #-1
7+
; CHECK-64: v0 = vand([[REG1]],[[REG2]])
8+
; CHECK-128: r{{[0-9]+}}:{{[0-9]+}} = combine(##.LCPI0_0,#-1)
9+
; CHECK-128: [[REG1:(q[0-9]+)]] = vcmp.eq(v0.b,v1.b)
10+
; CHECK-128: [[REG2:(v[0-9]+)]] = vand([[REG1]],r{{[0-9]+}})
11+
; CHECK-128: [[REG3:(v[0-9]+)]] = vmem(r{{[0-9]+}}+#0)
12+
; CHECK-128: [[REG4:(v[0-9]+)]] = vdelta([[REG2]],[[REG3]])
13+
; CHECK-128: [[REG5:(q[0-9]+)]] = vand([[REG4]],r{{[0-9]+}})
14+
; CHECK-128: v0 = vand([[REG5]],r{{[0-9]+}})
15+
16+
define void @compare_vectors(<64 x i8> %a, <64 x i8> %b) {
17+
entry:
18+
%result = icmp eq <64 x i8> %a, %b
19+
call i32 @f.1(<64 x i1> %result)
20+
ret void
21+
}
22+
23+
; CHECK-LABEL: f.1:
24+
; CHECK-64: [[REG3:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
25+
; CHECK-64: [[REG4:(v[0-9]+)]] = vand([[REG3]],r{{[0-9]+}})
26+
; CHECK-64: r{{[0-9]+}} = vextract([[REG4]],r{{[0-9]+}})
27+
; CHECK-128: [[REG6:(q[0-9]+)]] = vand(v0,r{{[0-9]+}})
28+
; CHECK-128: [[REG7:(v[0-9]+)]] = vand([[REG6]],r{{[0-9]+}})
29+
; CHECK-128: r{{[0-9]+}} = vextract([[REG7]],r{{[0-9]+}})
30+
31+
define i32 @f.1(<64 x i1> %vec) {
32+
%element = extractelement <64 x i1> %vec, i32 6
33+
%is_true = icmp eq i1 %element, true
34+
br i1 %is_true, label %if_true, label %if_false
35+
36+
if_true:
37+
call void @action_if_true()
38+
br label %end
39+
40+
if_false:
41+
call void @action_if_false()
42+
br label %end
43+
44+
end:
45+
%result = phi i32 [1, %if_true], [0, %if_false]
46+
ret i32 %result
47+
}
48+
49+
declare void @action_if_true()
50+
declare void @action_if_false()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;RUN: llc -mtriple=hexagon < %s -o - | FileCheck %s --check-prefix=CHECK
2+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length64b < %s -o - | FileCheck %s --check-prefix=CHECK
3+
;RUN: llc -mtriple=hexagon -mattr=+hvxv79,+hvx-length128b < %s -o - | FileCheck %s --check-prefix=CHECK
4+
5+
; CHECK-LABEL: compare_vectors
6+
; CHECK: [[REG0:(p[0-9]+)]] = vcmpb.eq([[REG1:(r[0-9]+):[0-9]]],[[REG2:(r[0-9]+):[0-9]]])
7+
; CHECK: [[REG1:(r[0-9]+):[0-9]]] = CONST64(#72340172838076673)
8+
; CHECK: [[REG2:(r[0-9]+):[0-9]]] = mask([[REG0]])
9+
; CHECK: r{{[0-9]+}}:{{[0-9]+}} = and([[REG2]],[[REG1]])
10+
11+
define void @compare_vectors(<8 x i8> %a, <8 x i8> %b) {
12+
entry:
13+
%result = icmp eq <8 x i8> %a, %b
14+
call i32 @f.1(<8 x i1> %result)
15+
ret void
16+
}
17+
; CHECK-LABEL: f.1:
18+
; CHECK: [[REG3:(r[0-9]+)]] = and([[REG3]],##16843009)
19+
; CHECK: [[REG4:(r[0-9]+)]] = and([[REG4]],##16843009)
20+
define i32 @f.1(<8 x i1> %vec) {
21+
%element = extractelement <8 x i1> %vec, i32 6
22+
%is_true = icmp eq i1 %element, true
23+
br i1 %is_true, label %if_true, label %if_false
24+
25+
if_true:
26+
call void @action_if_true()
27+
br label %end
28+
29+
if_false:
30+
call void @action_if_false()
31+
br label %end
32+
33+
end:
34+
%result = phi i32 [1, %if_true], [0, %if_false]
35+
ret i32 %result
36+
}
37+
38+
declare void @action_if_true()
39+
declare void @action_if_false()

0 commit comments

Comments
 (0)