forked from wangliu-iscas/gcc-patch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rs6000: Add new patterns rlwinm with mask
Hi, For code: ``` u64 test_rlwinm_lowpart_mask (u32 v) { u32 v1 = ((v << N) | (v >> (32 - N))) & 0xfffff00; return (u64)v1; } ``` We generate "rlwinm 3,3,4,4,23; rldicl 3,3,0,32" instead of "rlwinm 3,3,4,4,23". Here the "rlwinm" cleans high32 bits already, so "rldicl" is reductant. Similarly, for the below code which is the functionality of "rlwinm". ``` u64 test_rlwinm_mask (u32 v) { u32 v1 = ((v << N) | (v >> (32 - N))); u64 v2 = (u64) v1 | ((u64) v1 << 32); return v2 & 0xffffffffe0000003ULL; } ``` We generate "rotlwi 3,3,4; sldi 9,3,32; add 3,9,3; rldicl 3,3,35,27; rldicl 3,3,29,0" instead of "rlwinm 3,3,4,30,2". This patch optimizes these two kinds of code to use just one "rlwinm" insn. Bootstrap and regtests pass on ppc64{,le}. Is this patch ok for trunk (or next stage1)? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/predicates.md (lowpart_subreg_operand): New define_predicate. * config/rs6000/rs6000.md (rlwinm_lowpart_mask): New define_insn. (rlwinm_mask_<code>): New define_insn. gcc/testsuite/ChangeLog: * gcc.target/powerpc/rlwinm-0.c: Reduce instruction number. * gcc.target/powerpc/rlwinm_3.c: New test.
- Loading branch information
1 parent
295adfc
commit 2185464
Showing
4 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* { dg-do run } */ | ||
/* { dg-options "-O2 -save-temps" } */ | ||
|
||
typedef unsigned long long u64; | ||
typedef unsigned int u32; | ||
#define NOINLE __attribute__ ((noinline)) | ||
#define V (0x9753) | ||
|
||
#define MASK 0xffffffffe0000003ULL | ||
#define N 4 | ||
#define LMASK 0xfffff00 | ||
|
||
u64 NOINLE | ||
test_rlwinm_lowpart_mask (u32 v) | ||
{ | ||
u32 v1 = ((v << N) | (v >> (32 - N))) & LMASK; | ||
return (u64)v1; | ||
} | ||
|
||
u64 NOINLE | ||
test_rlwinm_mask (u32 v) | ||
{ | ||
u32 v1 = ((v << N) | (v >> (32 - N))); | ||
u64 v2 = (u64) v1 | ((u64) v1 << 32); | ||
return v2 & MASK; | ||
} | ||
|
||
/* { dg-final { scan-assembler-times {\mrlwinm\M} 2 { target has_arch_ppc64 } } } */ | ||
|
||
#define RLWINM_L(v, n) \ | ||
((((v & 0xffffffffLL) << n) | ((v & 0xffffffffLL) >> (32 - n))) \ | ||
& 0xffffffffLL) | ||
#define RLWINM_MASK(v, n, m) (((RLWINM_L (v, n) << 32) | (RLWINM_L (v, n))) & m) | ||
|
||
u64 v_low_mask = RLWINM_MASK (V, N, LMASK); | ||
u64 v_mask = RLWINM_MASK (V, N, MASK); | ||
|
||
int | ||
main () | ||
{ | ||
u64 v = V; | ||
if (test_rlwinm_lowpart_mask (v) != v_low_mask | ||
|| test_rlwinm_mask (v) != v_mask) | ||
__builtin_abort (); | ||
|
||
return 0; | ||
} |