aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHongyu Wang <hongyu.wang@intel.com>2023-10-31 14:21:16 +0800
committerHongyu Wang <hongyu.wang@intel.com>2023-12-07 09:31:15 +0800
commitd1dea413ef3761335bd741263a61e0f31e67b7d6 (patch)
treef0503a696b90f9d69050886d3e6be32aef818d84 /gcc
parent16172db2dfc6307860c545aa95897b84d8e157e1 (diff)
downloadgcc-d1dea413ef3761335bd741263a61e0f31e67b7d6.zip
gcc-d1dea413ef3761335bd741263a61e0f31e67b7d6.tar.gz
gcc-d1dea413ef3761335bd741263a61e0f31e67b7d6.tar.bz2
[APX NDD] Support APX NDD for rotate insns
gcc/ChangeLog: * config/i386/i386.md (*<insn><mode>3_1): Extend with a new alternative to support NDD for SI/DI rotate, and adjust output template. (*<insn>si3_1_zext): Likewise. (*<insn><mode>3_1): Likewise for QI/HI modes. (rcrsi2): Likewise, and use nonimmediate_operand for operands[1] to accept memory input for NDD alternative. (rcrdi2): Likewise. gcc/testsuite/ChangeLog: * gcc.target/i386/apx-ndd.c: Add test for left/right rotate.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/i386/i386.md79
-rw-r--r--gcc/testsuite/gcc.target/i386/apx-ndd.c20
2 files changed, 69 insertions, 30 deletions
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index d1eae72..6e4ac77 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -16667,13 +16667,15 @@
(set_attr "mode" "<MODE>")])
(define_insn "*<insn><mode>3_1"
- [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r")
+ [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r,r")
(any_rotate:SWI48
- (match_operand:SWI48 1 "nonimmediate_operand" "0,rm")
- (match_operand:QI 2 "nonmemory_operand" "c<S>,<S>")))
+ (match_operand:SWI48 1 "nonimmediate_operand" "0,rm,rm")
+ (match_operand:QI 2 "nonmemory_operand" "c<S>,<S>,c<S>")))
(clobber (reg:CC FLAGS_REG))]
- "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
+ "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands,
+ TARGET_APX_NDD)"
{
+ bool use_ndd = get_attr_isa (insn) == ISA_APX_NDD;
switch (get_attr_type (insn))
{
case TYPE_ROTATEX:
@@ -16681,14 +16683,16 @@
default:
if (operands[2] == const1_rtx
- && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+ && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
+ && !use_ndd)
return "<rotate>{<imodesuffix>}\t%0";
else
- return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
+ return use_ndd ? "<rotate>{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}"
+ : "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
}
}
- [(set_attr "isa" "*,bmi2")
- (set_attr "type" "rotate,rotatex")
+ [(set_attr "isa" "*,bmi2,apx_ndd")
+ (set_attr "type" "rotate,rotatex,rotate")
(set (attr "preferred_for_size")
(cond [(eq_attr "alternative" "0")
(symbol_ref "true")]
@@ -16738,13 +16742,14 @@
(set_attr "mode" "SI")])
(define_insn "*<insn>si3_1_zext"
- [(set (match_operand:DI 0 "register_operand" "=r,r")
+ [(set (match_operand:DI 0 "register_operand" "=r,r,r")
(zero_extend:DI
- (any_rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
- (match_operand:QI 2 "nonmemory_operand" "cI,I"))))
+ (any_rotate:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm,rm")
+ (match_operand:QI 2 "nonmemory_operand" "cI,I,cI"))))
(clobber (reg:CC FLAGS_REG))]
"TARGET_64BIT && ix86_binary_operator_ok (<CODE>, SImode, operands)"
{
+ bool use_ndd = get_attr_isa (insn) == ISA_APX_NDD;
switch (get_attr_type (insn))
{
case TYPE_ROTATEX:
@@ -16752,14 +16757,16 @@
default:
if (operands[2] == const1_rtx
- && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+ && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
+ && !use_ndd)
return "<rotate>{l}\t%k0";
else
- return "<rotate>{l}\t{%2, %k0|%k0, %2}";
+ return use_ndd ? "<rotate>{l}\t{%2, %1, %k0|%k0, %1, %2}"
+ : "<rotate>{l}\t{%2, %k0|%k0, %2}";
}
}
- [(set_attr "isa" "*,bmi2")
- (set_attr "type" "rotate,rotatex")
+ [(set_attr "isa" "*,bmi2,apx_ndd")
+ (set_attr "type" "rotate,rotatex,rotate")
(set (attr "preferred_for_size")
(cond [(eq_attr "alternative" "0")
(symbol_ref "true")]
@@ -16803,19 +16810,25 @@
(zero_extend:DI (rotatert:SI (match_dup 1) (match_dup 2))))])
(define_insn "*<insn><mode>3_1"
- [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m")
- (any_rotate:SWI12 (match_operand:SWI12 1 "nonimmediate_operand" "0")
- (match_operand:QI 2 "nonmemory_operand" "c<S>")))
+ [(set (match_operand:SWI12 0 "nonimmediate_operand" "=<r>m,r")
+ (any_rotate:SWI12 (match_operand:SWI12 1 "nonimmediate_operand" "0,rm")
+ (match_operand:QI 2 "nonmemory_operand" "c<S>,c<S>")))
(clobber (reg:CC FLAGS_REG))]
- "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
+ "ix86_binary_operator_ok (<CODE>, <MODE>mode, operands,
+ TARGET_APX_NDD)"
{
+ bool use_ndd = get_attr_isa (insn) == ISA_APX_NDD;
if (operands[2] == const1_rtx
- && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun)))
+ && (TARGET_SHIFT1 || optimize_function_for_size_p (cfun))
+ && !use_ndd)
return "<rotate>{<imodesuffix>}\t%0";
else
- return "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
+ return use_ndd
+ ? "<rotate>{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}"
+ : "<rotate>{<imodesuffix>}\t{%2, %0|%0, %2}";
}
- [(set_attr "type" "rotate")
+ [(set_attr "isa" "*,apx_ndd")
+ (set_attr "type" "rotate")
(set (attr "length_immediate")
(if_then_else
(and (match_operand 2 "const1_operand")
@@ -16872,31 +16885,37 @@
;; Rotations through carry flag
(define_insn "rcrsi2"
- [(set (match_operand:SI 0 "register_operand" "=r")
+ [(set (match_operand:SI 0 "register_operand" "=r,r")
(plus:SI
- (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
+ (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand" "0,rm")
(const_int 1))
(ashift:SI (ltu:SI (reg:CCC FLAGS_REG) (const_int 0))
(const_int 31))))
(clobber (reg:CC FLAGS_REG))]
""
- "rcr{l}\t%0"
- [(set_attr "type" "ishift1")
+ "@
+ rcr{l}\t%0
+ rcr{l}\t{%1, %0|%0, %1}"
+ [(set_attr "isa" "*,apx_ndd")
+ (set_attr "type" "ishift1")
(set_attr "memory" "none")
(set_attr "length_immediate" "0")
(set_attr "mode" "SI")])
(define_insn "rcrdi2"
- [(set (match_operand:DI 0 "register_operand" "=r")
+ [(set (match_operand:DI 0 "register_operand" "=r,r")
(plus:DI
- (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
+ (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "0,rm")
(const_int 1))
(ashift:DI (ltu:DI (reg:CCC FLAGS_REG) (const_int 0))
(const_int 63))))
(clobber (reg:CC FLAGS_REG))]
"TARGET_64BIT"
- "rcr{q}\t%0"
- [(set_attr "type" "ishift1")
+ "@
+ rcr{q}\t%0
+ rcr{q}\t{%1, %0|%0, %1}"
+ [(set_attr "isa" "*,apx_ndd")
+ (set_attr "type" "ishift1")
(set_attr "length_immediate" "0")
(set_attr "mode" "DI")])
diff --git a/gcc/testsuite/gcc.target/i386/apx-ndd.c b/gcc/testsuite/gcc.target/i386/apx-ndd.c
index 239c427..b215f66 100644
--- a/gcc/testsuite/gcc.target/i386/apx-ndd.c
+++ b/gcc/testsuite/gcc.target/i386/apx-ndd.c
@@ -40,6 +40,14 @@ foo3_##OP_NAME##_##TYPE (TYPE a) \
return b; \
}
+#define FOO4(TYPE, OP_NAME, OP1, OP2, IMM1) \
+TYPE \
+__attribute__ ((noipa)) \
+foo4_##OP_NAME##_##TYPE (TYPE a) \
+{ \
+ TYPE b = (a OP1 IMM1 | a OP2 (8 * sizeof(TYPE) - IMM1)); \
+ return b; \
+}
#define F(TYPE, OP_NAME, OP) \
TYPE \
@@ -152,6 +160,16 @@ FOO3 (uint32_t, shr, >>, 7)
FOO (uint64_t, shr, >>)
FOO3 (uint64_t, shr, >>, 7)
+FOO4 (uint8_t, ror, >>, <<, 1)
+FOO4 (uint16_t, ror, >>, <<, 1)
+FOO4 (uint32_t, ror, >>, <<, 1)
+FOO4 (uint64_t, ror, >>, <<, 1)
+
+FOO4 (uint8_t, rol, <<, >>, 1)
+FOO4 (uint16_t, rol, <<, >>, 1)
+FOO4 (uint32_t, rol, <<, >>, 1)
+FOO4 (uint64_t, rol, <<, >>, 1)
+
/* { dg-final { scan-assembler-times "add(?:b|l|w|q)\[^\n\r]*1, \\(%rdi\\), %(?:|r|e)a(?:x|l)" 4 } } */
/* { dg-final { scan-assembler-times "lea(?:l|q)\[^\n\r]\\(%r(?:d|s)i,%r(?:d|s)i\\), %(?:|r|e)ax" 4 } } */
/* { dg-final { scan-assembler-times "add(?:b|l|w|q)\[^\n\r]%(?:|r|e)si(?:|l), \\(%rdi\\), %(?:|r|e)a(?:x|l)" 4 } } */
@@ -180,3 +198,5 @@ FOO3 (uint64_t, shr, >>, 7)
/* { dg-final { scan-assembler-times "sar(?:b|l|w|q)\[^\n\r]*7, %(?:|r|e)di(?:|l), %(?:|r|e)a(?:x|l)" 4 } } */
/* { dg-final { scan-assembler-times "shr(?:b|l|w|q)\[^\n\r]*1, \\(%rdi\\), %(?:|r|e)a(?:x|l)" 4 } } */
/* { dg-final { scan-assembler-times "shr(?:b|l|w|q)\[^\n\r]*7, %(?:|r|e)di(?:|l), %(?:|r|e)a(?:x|l)" 4 } } */
+/* { dg-final { scan-assembler-times "ror(?:b|l|w|q)\[^\n\r]*1, %(?:|r|e)di(?:|l), %(?:|r|e)a(?:x|l)" 4 } } */
+/* { dg-final { scan-assembler-times "rol(?:b|l|w|q)\[^\n\r]*1, %(?:|r|e)di(?:|l), %(?:|r|e)a(?:x|l)" 4 } } */