Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 31407d3

Browse files
author
Krzysztof Parzyszek
committed
[Hexagon] Adjust patterns to reflect instruction selection preferences
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316804 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8822399 commit 31407d3

File tree

3 files changed

+89
-9
lines changed

3 files changed

+89
-9
lines changed

lib/Target/Hexagon/HexagonPatterns.td

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,14 @@ def: AccRRR_pat<M4_xor_or, Xor, Su<Or>, I32, I32>;
13011301
def: AccRRR_pat<M2_xor_xacc, Xor, Su<Xor>, I32, I32>;
13021302
def: AccRRR_pat<M4_xor_xacc, Xor, Su<Xor>, I64, I64>;
13031303

1304-
def: AccRRR_pat<M4_and_andn, And, Su<Not2<And>>, I32, I32>;
1305-
def: AccRRR_pat<M4_or_andn, Or, Su<Not2<And>>, I32, I32>;
1306-
def: AccRRR_pat<M4_xor_andn, Xor, Su<Not2<And>>, I32, I32>;
1304+
// For dags like (or (and (not _), _), (shl _, _)) where the "or" with
1305+
// one argument matches the patterns below, and with the other argument
1306+
// matches S2_asl_r_r_or, etc, prefer the patterns below.
1307+
let AddedComplexity = 110 in { // greater than S2_asl_r_r_and/or/xor.
1308+
def: AccRRR_pat<M4_and_andn, And, Su<Not2<And>>, I32, I32>;
1309+
def: AccRRR_pat<M4_or_andn, Or, Su<Not2<And>>, I32, I32>;
1310+
def: AccRRR_pat<M4_xor_andn, Xor, Su<Not2<And>>, I32, I32>;
1311+
}
13071312

13081313
// S4_addaddi and S4_subaddi don't have tied operands, so give them
13091314
// a bit of preference.
@@ -1418,10 +1423,18 @@ def : Pat <(mulhs I64:$Rss, I64:$Rtt),
14181423
(A2_andp (S2_asr_i_p $Rss, 63), (ClearSign $Rtt)),
14191424
(A2_andp (S2_asr_i_p $Rtt, 63), (ClearSign $Rss))))>;
14201425

1421-
def: Pat<(add (Su<Mul> I32:$Rs, u6_0ImmPred:$U6), anyimm:$u6),
1422-
(M4_mpyri_addi imm:$u6, IntRegs:$Rs, imm:$U6)>;
1423-
def: Pat<(add (Su<Mul> I32:$Rs, I32:$Rt), anyimm:$u6),
1424-
(M4_mpyrr_addi imm:$u6, IntRegs:$Rs, IntRegs:$Rt)>;
1426+
// Prefer these instructions over M2_macsip/M2_macsin: the macsi* instructions
1427+
// will put the immediate addend into a register, while these instructions will
1428+
// use it directly. Such a construct does not appear in the middle of a gep,
1429+
// where M2_macsip would be preferable.
1430+
let AddedComplexity = 20 in {
1431+
def: Pat<(add (Su<Mul> I32:$Rs, u6_0ImmPred:$U6), anyimm:$u6),
1432+
(M4_mpyri_addi imm:$u6, IntRegs:$Rs, imm:$U6)>;
1433+
def: Pat<(add (Su<Mul> I32:$Rs, I32:$Rt), anyimm:$u6),
1434+
(M4_mpyrr_addi imm:$u6, IntRegs:$Rs, IntRegs:$Rt)>;
1435+
}
1436+
1437+
// Keep these instructions less preferable to M2_macsip/M2_macsin.
14251438
def: Pat<(add I32:$Ru, (Su<Mul> I32:$Rs, u6_2ImmPred:$u6_2)),
14261439
(M4_mpyri_addr_u2 IntRegs:$Ru, imm:$u6_2, IntRegs:$Rs)>;
14271440
def: Pat<(add I32:$Ru, (Su<Mul> I32:$Rs, anyimm:$u6)),
@@ -1599,6 +1612,16 @@ def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), 0)),
15991612
def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), I32:$Rt)),
16001613
(C4_nbitsset I32:$Rs, I32:$Rt)>;
16011614

1615+
// Special patterns to address certain cases where the "top-down" matching
1616+
// algorithm would cause suboptimal selection.
1617+
1618+
let AddedComplexity = 100 in {
1619+
// Avoid A4_rcmp[n]eqi in these cases:
1620+
def: Pat<(i32 (zext (i1 (setne (and (shl 1, I32:$Rt), I32:$Rs), 0)))),
1621+
(I1toI32 (S2_tstbit_r IntRegs:$Rs, IntRegs:$Rt))>;
1622+
def: Pat<(i32 (zext (i1 (seteq (and (shl 1, I32:$Rt), I32:$Rs), 0)))),
1623+
(I1toI32 (S4_ntstbit_r IntRegs:$Rs, IntRegs:$Rt))>;
1624+
}
16021625

16031626
// --(11) Load -----------------------------------------------------------
16041627
//

test/CodeGen/Hexagon/isel-prefer.ll

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: llc -march=hexagon < %s | FileCheck %s
2+
3+
@data1 = external global [2 x [31 x i8]], align 8
4+
@data2 = external global [2 x [91 x i8]], align 8
5+
6+
; CHECK-LABEL: Prefer_M4_or_andn:
7+
; CHECK: r2 |= and(r0,~r1)
8+
define i32 @Prefer_M4_or_andn(i32 %a0, i32 %a1, i32 %a2) #0 {
9+
b3:
10+
%v4 = xor i32 %a1, -1
11+
%v5 = shl i32 %a2, 5
12+
%v6 = and i32 %a0, %v4
13+
%v7 = or i32 %v6, %v5
14+
ret i32 %v7
15+
}
16+
17+
; CHECK-LABEL: Prefer_M4_mpyri_addi:
18+
; CHECK: add(##data1,mpyi(r0,#31))
19+
define i32 @Prefer_M4_mpyri_addi(i32 %a0) #0 {
20+
b1:
21+
%v2 = getelementptr inbounds [2 x [31 x i8]], [2 x [31 x i8]]* @data1, i32 0, i32 %a0
22+
%v3 = ptrtoint [31 x i8]* %v2 to i32
23+
ret i32 %v3
24+
}
25+
26+
; CHECK-LABEL: Prefer_M4_mpyrr_addi:
27+
; CHECK: add(##data2,mpyi(r0,r1))
28+
define i32 @Prefer_M4_mpyrr_addi(i32 %a0) #0 {
29+
b1:
30+
%v2 = getelementptr inbounds [2 x [91 x i8]], [2 x [91 x i8]]* @data2, i32 0, i32 %a0
31+
%v3 = ptrtoint [91 x i8]* %v2 to i32
32+
ret i32 %v3
33+
}
34+
35+
; CHECK-LABEL: Prefer_S2_tstbit_r:
36+
; CHECK: p0 = tstbit(r0,r1)
37+
define i32 @Prefer_S2_tstbit_r(i32 %a0, i32 %a1) #0 {
38+
b2:
39+
%v3 = shl i32 1, %a1
40+
%v4 = and i32 %a0, %v3
41+
%v5 = icmp ne i32 %v4, 0
42+
%v6 = zext i1 %v5 to i32
43+
ret i32 %v6
44+
}
45+
46+
; CHECK-LABEL: Prefer_S2_ntstbit_r:
47+
; CHECK: p0 = !tstbit(r0,r1)
48+
define i32 @Prefer_S2_ntstbit_r(i32 %a0, i32 %a1) #0 {
49+
b2:
50+
%v3 = shl i32 1, %a1
51+
%v4 = and i32 %a0, %v3
52+
%v5 = icmp eq i32 %v4, 0
53+
%v6 = zext i1 %v5 to i32
54+
ret i32 %v6
55+
}
56+
57+
attributes #0 = { nounwind readnone }

test/CodeGen/Hexagon/swp-stages4.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
; CHECK: loop0(.LBB0_[[LOOP:.]],
1212
; CHECK: .LBB0_[[LOOP]]:
1313
; CHECK: [[REG0]] += add
14+
; CHECK: [[REG2:r[0-9]+]] = and
1415
; CHECK: = and
15-
; CHECK: = and
16-
; CHECK: [[REG0]] = and
16+
; CHECK: [[REG0]] = [[REG2]]
1717
; CHECK: endloop
1818

1919
; Function Attrs: nounwind

0 commit comments

Comments
 (0)