Skip to content

Commit a5d161c

Browse files
LemonBoyMaskRay
authored andcommitted
[PowerPC] Don't use rldicl for PPC32
According to https://www.ibm.com/support/knowledgecenter/ssw_aix_72/assembler/idalangref_rldicl_rletdw_instrs.html rldicl should not be used when targeting 32bit CPUs. Reviewed By: #powerpc, nemanjai, MaskRay Differential Revision: https://reviews.llvm.org/D77946
1 parent 2f2667b commit a5d161c

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.td

+5-2
Original file line numberDiff line numberDiff line change
@@ -5068,8 +5068,11 @@ def RotateInsertByte1 {
50685068
dag Left = (RLWIMI RotateInsertByte3.Left, Swap4.Bits, 8, 24, 31);
50695069
}
50705070

5071-
def : Pat<(i32 (bitreverse i32:$A)),
5072-
(RLDICL_32 RotateInsertByte1.Left, 0, 32)>;
5071+
// Clear the upper half of the register when in 64-bit mode
5072+
let Predicates = [In64BitMode] in
5073+
def : Pat<(i32 (bitreverse i32:$A)), (RLDICL_32 RotateInsertByte1.Left, 0, 32)>;
5074+
let Predicates = [In32BitMode] in
5075+
def : Pat<(i32 (bitreverse i32:$A)), RotateInsertByte1.Left>;
50735076

50745077
// Fast 64-bit reverse bits algorithm:
50755078
// Step 1: 1-bit swap (swap odd 1-bit and even 1-bit):

llvm/test/CodeGen/PowerPC/testBitReverse.ll

+87
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -verify-machineinstrs -mtriple=powerpc -mcpu=ppc32 < %s | FileCheck %s --check-prefix=PPC32
23
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
34
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
45
declare i32 @llvm.bitreverse.i32(i32)
56
define i32 @testBitReverseIntrinsicI32(i32 %arg) {
7+
; PPC32-LABEL: testBitReverseIntrinsicI32:
8+
; PPC32: # %bb.0:
9+
; PPC32-NEXT: lis 4, -21846
10+
; PPC32-NEXT: ori 4, 4, 43690
11+
; PPC32-NEXT: slwi 5, 3, 1
12+
; PPC32-NEXT: and 4, 5, 4
13+
; PPC32-NEXT: lis 5, 21845
14+
; PPC32-NEXT: ori 5, 5, 21845
15+
; PPC32-NEXT: srwi 3, 3, 1
16+
; PPC32-NEXT: and 3, 3, 5
17+
; PPC32-NEXT: lis 5, -13108
18+
; PPC32-NEXT: or 3, 3, 4
19+
; PPC32-NEXT: ori 5, 5, 52428
20+
; PPC32-NEXT: slwi 4, 3, 2
21+
; PPC32-NEXT: and 4, 4, 5
22+
; PPC32-NEXT: lis 5, 13107
23+
; PPC32-NEXT: ori 5, 5, 13107
24+
; PPC32-NEXT: srwi 3, 3, 2
25+
; PPC32-NEXT: and 3, 3, 5
26+
; PPC32-NEXT: lis 5, -3856
27+
; PPC32-NEXT: or 3, 3, 4
28+
; PPC32-NEXT: ori 5, 5, 61680
29+
; PPC32-NEXT: slwi 4, 3, 4
30+
; PPC32-NEXT: and 4, 4, 5
31+
; PPC32-NEXT: lis 5, 3855
32+
; PPC32-NEXT: ori 5, 5, 3855
33+
; PPC32-NEXT: srwi 3, 3, 4
34+
; PPC32-NEXT: and 3, 3, 5
35+
; PPC32-NEXT: or 4, 3, 4
36+
; PPC32-NEXT: rotlwi 3, 4, 24
37+
; PPC32-NEXT: rlwimi 3, 4, 8, 8, 15
38+
; PPC32-NEXT: rlwimi 3, 4, 8, 24, 31
39+
; PPC32-NEXT: blr
40+
;
641
; CHECK-LABEL: testBitReverseIntrinsicI32:
742
; CHECK: # %bb.0:
843
; CHECK-NEXT: lis 4, -21846
@@ -43,6 +78,58 @@ define i32 @testBitReverseIntrinsicI32(i32 %arg) {
4378

4479
declare i64 @llvm.bitreverse.i64(i64)
4580
define i64 @testBitReverseIntrinsicI64(i64 %arg) {
81+
; PPC32-LABEL: testBitReverseIntrinsicI64:
82+
; PPC32: # %bb.0:
83+
; PPC32-NEXT: lis 5, -21846
84+
; PPC32-NEXT: lis 6, 21845
85+
; PPC32-NEXT: ori 5, 5, 43690
86+
; PPC32-NEXT: slwi 10, 4, 1
87+
; PPC32-NEXT: slwi 11, 3, 1
88+
; PPC32-NEXT: ori 6, 6, 21845
89+
; PPC32-NEXT: srwi 4, 4, 1
90+
; PPC32-NEXT: srwi 3, 3, 1
91+
; PPC32-NEXT: and 10, 10, 5
92+
; PPC32-NEXT: and 5, 11, 5
93+
; PPC32-NEXT: and 4, 4, 6
94+
; PPC32-NEXT: and 3, 3, 6
95+
; PPC32-NEXT: lis 7, -13108
96+
; PPC32-NEXT: lis 8, 13107
97+
; PPC32-NEXT: or 4, 4, 10
98+
; PPC32-NEXT: or 3, 3, 5
99+
; PPC32-NEXT: ori 7, 7, 52428
100+
; PPC32-NEXT: ori 8, 8, 13107
101+
; PPC32-NEXT: slwi 5, 4, 2
102+
; PPC32-NEXT: srwi 4, 4, 2
103+
; PPC32-NEXT: slwi 6, 3, 2
104+
; PPC32-NEXT: srwi 3, 3, 2
105+
; PPC32-NEXT: and 5, 5, 7
106+
; PPC32-NEXT: and 4, 4, 8
107+
; PPC32-NEXT: and 6, 6, 7
108+
; PPC32-NEXT: and 3, 3, 8
109+
; PPC32-NEXT: lis 9, -3856
110+
; PPC32-NEXT: lis 11, 3855
111+
; PPC32-NEXT: or 4, 4, 5
112+
; PPC32-NEXT: or 3, 3, 6
113+
; PPC32-NEXT: ori 9, 9, 61680
114+
; PPC32-NEXT: ori 11, 11, 3855
115+
; PPC32-NEXT: slwi 5, 4, 4
116+
; PPC32-NEXT: srwi 4, 4, 4
117+
; PPC32-NEXT: slwi 6, 3, 4
118+
; PPC32-NEXT: srwi 3, 3, 4
119+
; PPC32-NEXT: and 5, 5, 9
120+
; PPC32-NEXT: and 4, 4, 11
121+
; PPC32-NEXT: and 6, 6, 9
122+
; PPC32-NEXT: and 3, 3, 11
123+
; PPC32-NEXT: or 5, 4, 5
124+
; PPC32-NEXT: or 6, 3, 6
125+
; PPC32-NEXT: rotlwi 3, 5, 24
126+
; PPC32-NEXT: rotlwi 4, 6, 24
127+
; PPC32-NEXT: rlwimi 3, 5, 8, 8, 15
128+
; PPC32-NEXT: rlwimi 4, 6, 8, 8, 15
129+
; PPC32-NEXT: rlwimi 3, 5, 8, 24, 31
130+
; PPC32-NEXT: rlwimi 4, 6, 8, 24, 31
131+
; PPC32-NEXT: blr
132+
;
46133
; CHECK-LABEL: testBitReverseIntrinsicI64:
47134
; CHECK: # %bb.0:
48135
; CHECK-NEXT: lis 4, -21846

0 commit comments

Comments
 (0)