1 Star 0 Fork 132

wangding16/src-gcc

forked from src-openEuler/gcc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0070-Backport-aarch64-Fix-subs_compare_2.c-regression-PR1.patch 24.47 KB
一键复制 编辑 原始数据 按行查看 历史
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
From f6b6948de1d836b594ad388388b7121dd7a702cb Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Tue, 15 Feb 2022 18:09:35 +0000
Subject: [PATCH 22/35] [Backport] aarch64: Fix subs_compare_2.c regression
[PR100874]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reference: https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=8e84b2b37a541b27feea69769fc314d534464ebd
subs_compare_2.c tests that we can use a SUBS+CSEL sequence for:
unsigned int
foo (unsigned int a, unsigned int b)
{
unsigned int x = a - 4;
if (a < 4)
return x;
else
return 0;
}
As Andrew notes in the PR, this is effectively MIN (x, 4) - 4,
and it is now recognised as such by phiopt. Previously it was
if-converted in RTL instead.
I tried to look for ways to generalise this to other situations
and to other ?:-style operations, not just max and min. However,
for general ?: we tend to push an outer “- CST” into the arms of
the ?: -- at least if one of them simplifies -- so I didn't find
any useful abstraction.
This patch therefore adds a pattern specifically for
max/min(a,cst)-cst. I'm not thrilled at having to do this,
but it seems like the least worst fix in the circumstances.
Also, max(a,cst)-cst for unsigned a is a useful saturating
subtraction idiom and so is arguably worth its own code
for that reason.
gcc/
PR target/100874
* config/aarch64/aarch64-protos.h (aarch64_maxmin_plus_const):
Declare.
* config/aarch64/aarch64.cc (aarch64_maxmin_plus_const): New function.
* config/aarch64/aarch64.md (*aarch64_minmax_plus): New pattern.
gcc/testsuite/
* gcc.target/aarch64/max_plus_1.c: New test.
* gcc.target/aarch64/max_plus_2.c: Likewise.
* gcc.target/aarch64/max_plus_3.c: Likewise.
* gcc.target/aarch64/max_plus_4.c: Likewise.
* gcc.target/aarch64/max_plus_5.c: Likewise.
* gcc.target/aarch64/max_plus_6.c: Likewise.
* gcc.target/aarch64/max_plus_7.c: Likewise.
* gcc.target/aarch64/min_plus_1.c: Likewise.
* gcc.target/aarch64/min_plus_2.c: Likewise.
* gcc.target/aarch64/min_plus_3.c: Likewise.
* gcc.target/aarch64/min_plus_4.c: Likewise.
* gcc.target/aarch64/min_plus_5.c: Likewise.
* gcc.target/aarch64/min_plus_6.c: Likewise.
* gcc.target/aarch64/min_plus_7.c: Likewise.
---
gcc/config/aarch64/aarch64-protos.h | 1 +
gcc/config/aarch64/aarch64.c | 104 ++++++++++++
gcc/config/aarch64/aarch64.md | 27 ++++
gcc/testsuite/gcc.target/aarch64/max_plus_1.c | 149 ++++++++++++++++++
gcc/testsuite/gcc.target/aarch64/max_plus_2.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/max_plus_3.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/max_plus_4.c | 30 ++++
gcc/testsuite/gcc.target/aarch64/max_plus_5.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/max_plus_6.c | 9 ++
gcc/testsuite/gcc.target/aarch64/max_plus_7.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/min_plus_1.c | 149 ++++++++++++++++++
gcc/testsuite/gcc.target/aarch64/min_plus_2.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/min_plus_3.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/min_plus_4.c | 30 ++++
gcc/testsuite/gcc.target/aarch64/min_plus_5.c | 35 ++++
gcc/testsuite/gcc.target/aarch64/min_plus_6.c | 9 ++
gcc/testsuite/gcc.target/aarch64/min_plus_7.c | 35 ++++
17 files changed, 788 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_2.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_3.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_4.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_5.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_6.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/max_plus_7.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_1.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_2.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_3.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_4.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_5.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_6.c
create mode 100644 gcc/testsuite/gcc.target/aarch64/min_plus_7.c
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 226f3a8ff..9b6d309a7 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -696,6 +696,7 @@ bool aarch64_legitimate_address_p (machine_mode, rtx, bool,
aarch64_addr_query_type = ADDR_QUERY_M);
machine_mode aarch64_select_cc_mode (RTX_CODE, rtx, rtx);
rtx aarch64_gen_compare_reg (RTX_CODE, rtx, rtx);
+bool aarch64_maxmin_plus_const (rtx_code, rtx *, bool);
rtx aarch64_load_tp (rtx);
void aarch64_expand_compare_and_swap (rtx op[]);
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index f78942b04..85dbd3898 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -3038,6 +3038,110 @@ aarch64_gen_compare_reg_maybe_ze (RTX_CODE code, rtx x, rtx y,
return aarch64_gen_compare_reg (code, x, y);
}
+/* Consider the operation:
+
+ OPERANDS[0] = CODE (OPERANDS[1], OPERANDS[2]) + OPERANDS[3]
+
+ where:
+
+ - CODE is [SU]MAX or [SU]MIN
+ - OPERANDS[2] and OPERANDS[3] are constant integers
+ - OPERANDS[3] is a positive or negative shifted 12-bit immediate
+ - all operands have mode MODE
+
+ Decide whether it is possible to implement the operation using:
+
+ SUBS <tmp>, OPERANDS[1], -OPERANDS[3]
+ or
+ ADDS <tmp>, OPERANDS[1], OPERANDS[3]
+
+ followed by:
+
+ <insn> OPERANDS[0], <tmp>, [wx]zr, <cond>
+
+ where <insn> is one of CSEL, CSINV or CSINC. Return true if so.
+ If GENERATE_P is true, also update OPERANDS as follows:
+
+ OPERANDS[4] = -OPERANDS[3]
+ OPERANDS[5] = the rtl condition representing <cond>
+ OPERANDS[6] = <tmp>
+ OPERANDS[7] = 0 for CSEL, -1 for CSINV or 1 for CSINC. */
+bool
+aarch64_maxmin_plus_const (rtx_code code, rtx *operands, bool generate_p)
+{
+ signop sgn = (code == UMAX || code == UMIN ? UNSIGNED : SIGNED);
+ rtx dst = operands[0];
+ rtx maxmin_op = operands[2];
+ rtx add_op = operands[3];
+ machine_mode mode = GET_MODE (dst);
+
+ /* max (x, y) - z == (x >= y + 1 ? x : y) - z
+ == (x >= y ? x : y) - z
+ == (x > y ? x : y) - z
+ == (x > y - 1 ? x : y) - z
+
+ min (x, y) - z == (x <= y - 1 ? x : y) - z
+ == (x <= y ? x : y) - z
+ == (x < y ? x : y) - z
+ == (x < y + 1 ? x : y) - z
+
+ Check whether z is in { y - 1, y, y + 1 } and pick the form(s) for
+ which x is compared with z. Set DIFF to y - z. Thus the supported
+ combinations are as follows, with DIFF being the value after the ":":
+
+ max (x, y) - z == x >= y + 1 ? x - (y + 1) : -1 [z == y + 1]
+ == x >= y ? x - y : 0 [z == y]
+ == x > y ? x - y : 0 [z == y]
+ == x > y - 1 ? x - (y - 1) : 1 [z == y - 1]
+
+ min (x, y) - z == x <= y - 1 ? x - (y - 1) : 1 [z == y - 1]
+ == x <= y ? x - y : 0 [z == y]
+ == x < y ? x - y : 0 [z == y]
+ == x < y + 1 ? x - (y + 1) : -1 [z == y + 1]. */
+ auto maxmin_val = rtx_mode_t (maxmin_op, mode);
+ auto add_val = rtx_mode_t (add_op, mode);
+ auto sub_val = wi::neg (add_val);
+ auto diff = wi::sub (maxmin_val, sub_val);
+ if (!(diff == 0
+ || (diff == 1 && wi::gt_p (maxmin_val, sub_val, sgn))
+ || (diff == -1 && wi::lt_p (maxmin_val, sub_val, sgn))))
+ return false;
+
+ if (!generate_p)
+ return true;
+
+ rtx_code cmp;
+ switch (code)
+ {
+ case SMAX:
+ cmp = diff == 1 ? GT : GE;
+ break;
+ case UMAX:
+ cmp = diff == 1 ? GTU : GEU;
+ break;
+ case SMIN:
+ cmp = diff == -1 ? LT : LE;
+ break;
+ case UMIN:
+ cmp = diff == -1 ? LTU : LEU;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ rtx cc = gen_rtx_REG (CCmode, CC_REGNUM);
+
+ operands[4] = immed_wide_int_const (sub_val, mode);
+ operands[5] = gen_rtx_fmt_ee (cmp, VOIDmode, cc, const0_rtx);
+ if (can_create_pseudo_p ())
+ operands[6] = gen_reg_rtx (mode);
+ else
+ operands[6] = dst;
+ operands[7] = immed_wide_int_const (diff, mode);
+
+ return true;
+}
+
+
/* Build the SYMBOL_REF for __tls_get_addr. */
static GTY(()) rtx tls_get_addr_libfunc;
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index ee80261f1..7c2562f49 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4499,6 +4499,33 @@
}
)
+;; Implement MAX/MIN (A, B) - C using SUBS/ADDS followed by CSEL/CSINV/CSINC.
+;; See aarch64_maxmin_plus_const for details about the supported cases.
+(define_insn_and_split "*aarch64_minmax_plus"
+ [(set (match_operand:GPI 0 "register_operand" "=r")
+ (plus:GPI
+ (MAXMIN:GPI
+ (match_operand:GPI 1 "register_operand" "r")
+ (match_operand:GPI 2 "const_int_operand"))
+ (match_operand:GPI 3 "aarch64_plus_immediate")))
+ (clobber (reg:CC CC_REGNUM))]
+ "aarch64_maxmin_plus_const (<CODE>, operands, false)"
+ "#"
+ "&& 1"
+ [(parallel
+ [(set (reg:CC CC_REGNUM)
+ (compare:CC (match_dup 1) (match_dup 4)))
+ (set (match_dup 6)
+ (plus:GPI (match_dup 1) (match_dup 3)))])
+ (set (match_dup 0)
+ (if_then_else:GPI (match_dup 5) (match_dup 6) (match_dup 7)))]
+ {
+ if (!aarch64_maxmin_plus_const (<CODE>, operands, true))
+ gcc_unreachable ();
+ }
+ [(set_attr "length" "8")]
+)
+
;; -------------------------------------------------------------------
;; Logical operations
;; -------------------------------------------------------------------
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_1.c b/gcc/testsuite/gcc.target/aarch64/max_plus_1.c
new file mode 100644
index 000000000..ef336aeec
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_1.c
@@ -0,0 +1,149 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (w[0-9]+), w0, #4
+** csel w0, \1, wzr, g[te]
+** ret
+*/
+/*
+** f2:
+** adds (w[0-9]+), w0, #4
+** csel w0, \1, wzr, g[te]
+** ret
+*/
+/*
+** f3:
+** adds (w[0-9]+), w0, #5
+** csinc w0, \1, wzr, gt
+** ret
+*/
+/*
+** f4:
+** adds (w[0-9]+), w0, #3
+** csinv w0, \1, wzr, ge
+** ret
+*/
+
+#ifndef TYPE
+#define TYPE int32_t
+#define TYPE_MIN INT32_MIN
+#define TYPE_MAX INT32_MAX
+#define VALUE -4
+#endif
+
+#include <stdint.h>
+
+TYPE __attribute__((noipa))
+f1 (TYPE x)
+{
+ return (x > VALUE ? x - VALUE : 0);
+}
+
+TYPE __attribute__((noipa))
+f2 (TYPE x)
+{
+ return (x > VALUE ? x : VALUE) - VALUE;
+}
+
+TYPE __attribute__((noipa))
+f3 (TYPE x)
+{
+ return (x > VALUE ? x : VALUE) - (VALUE - 1);
+}
+
+TYPE __attribute__((noipa))
+f4 (TYPE x)
+{
+ return (x > VALUE ? x : VALUE) - (VALUE + 1);
+}
+
+TYPE __attribute__((noipa))
+f5 (TYPE x)
+{
+ return (x > VALUE ? x : VALUE) - (VALUE + 2);
+}
+
+TYPE __attribute__((noipa))
+f6 (TYPE x)
+{
+ return (x > VALUE ? x : VALUE) - (VALUE - 2);
+}
+
+int
+main (void)
+{
+ TYPE max_test = TYPE_MAX;
+ if (TYPE_MIN < 0 && VALUE < 0)
+ max_test += VALUE;
+
+ if (f1 (TYPE_MIN) != 0)
+ __builtin_abort ();
+ if (f1 (VALUE - 1) != 0)
+ __builtin_abort ();
+ if (f1 (VALUE) != 0)
+ __builtin_abort ();
+ if (f1 (VALUE + 1) != 1)
+ __builtin_abort ();
+ if (f1 (max_test) != max_test - VALUE)
+ __builtin_abort ();
+
+ if (f2 (TYPE_MIN) != 0)
+ __builtin_abort ();
+ if (f2 (VALUE - 1) != 0)
+ __builtin_abort ();
+ if (f2 (VALUE) != 0)
+ __builtin_abort ();
+ if (f2 (VALUE + 1) != 1)
+ __builtin_abort ();
+ if (f2 (max_test) != max_test - VALUE)
+ __builtin_abort ();
+
+ if (f3 (TYPE_MIN) != 1)
+ __builtin_abort ();
+ if (f3 (VALUE - 1) != 1)
+ __builtin_abort ();
+ if (f3 (VALUE) != 1)
+ __builtin_abort ();
+ if (f3 (VALUE + 1) != 2)
+ __builtin_abort ();
+ if (f3 (max_test - 1) != max_test - VALUE)
+ __builtin_abort ();
+
+ if (f4 (TYPE_MIN) != -1)
+ __builtin_abort ();
+ if (f4 (VALUE - 1) != -1)
+ __builtin_abort ();
+ if (f4 (VALUE) != -1)
+ __builtin_abort ();
+ if (f4 (VALUE + 1) != 0)
+ __builtin_abort ();
+ if (f4 (max_test) != max_test - VALUE - 1)
+ __builtin_abort ();
+
+ if (f5 (TYPE_MIN) != -2)
+ __builtin_abort ();
+ if (f5 (VALUE - 1) != -2)
+ __builtin_abort ();
+ if (f5 (VALUE) != -2)
+ __builtin_abort ();
+ if (f5 (VALUE + 1) != -1)
+ __builtin_abort ();
+ if (f5 (max_test) != max_test - VALUE - 2)
+ __builtin_abort ();
+
+ if (f6 (TYPE_MIN) != 2)
+ __builtin_abort ();
+ if (f6 (VALUE - 1) != 2)
+ __builtin_abort ();
+ if (f6 (VALUE) != 2)
+ __builtin_abort ();
+ if (f6 (VALUE + 1) != 3)
+ __builtin_abort ();
+ if (VALUE <= max_test - 2 && f6 (max_test - 2) != max_test - VALUE)
+ __builtin_abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_2.c b/gcc/testsuite/gcc.target/aarch64/max_plus_2.c
new file mode 100644
index 000000000..a2a1295d9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_2.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (x[0-9]+), x0, #4094
+** csel x0, \1, xzr, g[te]
+** ret
+*/
+/*
+** f2:
+** adds (x[0-9]+), x0, #4094
+** csel x0, \1, xzr, g[te]
+** ret
+*/
+/*
+** f3:
+** adds (x[0-9]+), x0, #4095
+** csinc x0, \1, xzr, gt
+** ret
+*/
+/*
+** f4:
+** adds (x[0-9]+), x0, #4093
+** csinv x0, \1, xzr, ge
+** ret
+*/
+
+#define TYPE int64_t
+#define TYPE_MIN INT64_MIN
+#define TYPE_MAX INT64_MAX
+#define VALUE -4094
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_3.c b/gcc/testsuite/gcc.target/aarch64/max_plus_3.c
new file mode 100644
index 000000000..a9792ecc9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_3.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (w[0-9]+), w0, #4095
+** csel w0, \1, wzr, g[te]
+** ret
+*/
+/*
+** f2:
+** adds (w[0-9]+), w0, #4095
+** csel w0, \1, wzr, g[te]
+** ret
+*/
+/*
+** f3:
+** adds (w[0-9]+), w0, #4096
+** csinc w0, \1, wzr, gt
+** ret
+*/
+/*
+** f4:
+** adds (w[0-9]+), w0, #4094
+** csinv w0, \1, wzr, ge
+** ret
+*/
+
+#define TYPE int32_t
+#define TYPE_MIN INT32_MIN
+#define TYPE_MAX INT32_MAX
+#define VALUE -4095
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_4.c b/gcc/testsuite/gcc.target/aarch64/max_plus_4.c
new file mode 100644
index 000000000..5090fa101
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_4.c
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (x[0-9]+), x0, #4096
+** csel x0, \1, xzr, g[te]
+** ret
+*/
+/*
+** f2:
+** adds (x[0-9]+), x0, #4096
+** csel x0, \1, xzr, g[te]
+** ret
+*/
+/* f3 out of range */
+/*
+** f4:
+** adds (x[0-9]+), x0, #4095
+** csinv x0, \1, xzr, ge
+** ret
+*/
+
+#define TYPE int64_t
+#define TYPE_MIN INT64_MIN
+#define TYPE_MAX INT64_MAX
+#define VALUE -4096
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_5.c b/gcc/testsuite/gcc.target/aarch64/max_plus_5.c
new file mode 100644
index 000000000..63f3b3442
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_5.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (w[0-9]+), w0, #4095
+** csel w0, \1, wzr, (cs|hi)
+** ret
+*/
+/*
+** f2:
+** adds (w[0-9]+), w0, #4095
+** csel w0, \1, wzr, (cs|hi)
+** ret
+*/
+/*
+** f3:
+** adds (w[0-9]+), w0, #4096
+** csinc w0, \1, wzr, hi
+** ret
+*/
+/*
+** f4:
+** adds (w[0-9]+), w0, #4094
+** csinv w0, \1, wzr, cs
+** ret
+*/
+
+#define TYPE uint32_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT32_MAX
+#define VALUE (uint32_t)-4095
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_6.c b/gcc/testsuite/gcc.target/aarch64/max_plus_6.c
new file mode 100644
index 000000000..ad592c690
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_6.c
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+
+#define TYPE uint64_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT64_MAX
+#define VALUE (uint64_t)-2
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/max_plus_7.c b/gcc/testsuite/gcc.target/aarch64/max_plus_7.c
new file mode 100644
index 000000000..ac9f27dec
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/max_plus_7.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** adds (x[0-9]+), x0, #3
+** csel x0, \1, xzr, (cs|hi)
+** ret
+*/
+/*
+** f2:
+** adds (x[0-9]+), x0, #3
+** csel x0, \1, xzr, (cs|hi)
+** ret
+*/
+/*
+** f3:
+** adds (x[0-9]+), x0, #4
+** csinc x0, \1, xzr, hi
+** ret
+*/
+/*
+** f4:
+** adds (x[0-9]+), x0, #2
+** csinv x0, \1, xzr, cs
+** ret
+*/
+
+#define TYPE uint64_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT64_MAX
+#define VALUE (uint64_t)-3
+
+#include "max_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_1.c b/gcc/testsuite/gcc.target/aarch64/min_plus_1.c
new file mode 100644
index 000000000..f4c9106df
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_1.c
@@ -0,0 +1,149 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (w[0-9]+), w0, #?4
+** csel w0, \1, wzr, l[te]
+** ret
+*/
+/*
+** f2:
+** subs (w[0-9]+), w0, #?4
+** csel w0, \1, wzr, l[te]
+** ret
+*/
+/*
+** f3:
+** subs (w[0-9]+), w0, #?3
+** csinc w0, \1, wzr, le
+** ret
+*/
+/*
+** f4:
+** subs (w[0-9]+), w0, #?5
+** csinv w0, \1, wzr, lt
+** ret
+*/
+
+#ifndef TYPE
+#define TYPE int32_t
+#define TYPE_MIN INT32_MIN
+#define TYPE_MAX INT32_MAX
+#define VALUE 4
+#endif
+
+#include <stdint.h>
+
+TYPE __attribute__((noipa))
+f1 (TYPE x)
+{
+ return (x < VALUE ? x - VALUE : 0);
+}
+
+TYPE __attribute__((noipa))
+f2 (TYPE x)
+{
+ return (x < VALUE ? x : VALUE) - VALUE;
+}
+
+TYPE __attribute__((noipa))
+f3 (TYPE x)
+{
+ return (x < VALUE ? x : VALUE) - (VALUE - 1);
+}
+
+TYPE __attribute__((noipa))
+f4 (TYPE x)
+{
+ return (x < VALUE ? x : VALUE) - (VALUE + 1);
+}
+
+TYPE __attribute__((noipa))
+f5 (TYPE x)
+{
+ return (x < VALUE ? x : VALUE) - (VALUE + 2);
+}
+
+TYPE __attribute__((noipa))
+f6 (TYPE x)
+{
+ return (x < VALUE ? x : VALUE) - (VALUE - 2);
+}
+
+int
+main (void)
+{
+ TYPE min_test = TYPE_MIN;
+ if (TYPE_MIN < 0 && VALUE > 0)
+ min_test += VALUE;
+
+ if (f1 (min_test) != min_test - VALUE)
+ __builtin_abort ();
+ if (f1 (VALUE - 1) != -1)
+ __builtin_abort ();
+ if (f1 (VALUE) != 0)
+ __builtin_abort ();
+ if (f1 (VALUE + 1) != 0)
+ __builtin_abort ();
+ if (f1 (TYPE_MAX) != 0)
+ __builtin_abort ();
+
+ if (f2 (min_test) != min_test - VALUE)
+ __builtin_abort ();
+ if (f2 (VALUE - 1) != -1)
+ __builtin_abort ();
+ if (f2 (VALUE) != 0)
+ __builtin_abort ();
+ if (f2 (VALUE + 1) != 0)
+ __builtin_abort ();
+ if (f2 (TYPE_MAX) != 0)
+ __builtin_abort ();
+
+ if (f3 (min_test) != min_test - VALUE + 1)
+ __builtin_abort ();
+ if (f3 (VALUE - 1) != 0)
+ __builtin_abort ();
+ if (f3 (VALUE) != 1)
+ __builtin_abort ();
+ if (f3 (VALUE + 1) != 1)
+ __builtin_abort ();
+ if (f3 (TYPE_MAX) != 1)
+ __builtin_abort ();
+
+ if (f4 (min_test + 1) != min_test - VALUE)
+ __builtin_abort ();
+ if (f4 (VALUE - 1) != -2)
+ __builtin_abort ();
+ if (f4 (VALUE) != -1)
+ __builtin_abort ();
+ if (f4 (VALUE + 1) != -1)
+ __builtin_abort ();
+ if (f4 (TYPE_MAX) != -1)
+ __builtin_abort ();
+
+ if (VALUE >= min_test + 2 && f5 (min_test + 2) != min_test - VALUE)
+ __builtin_abort ();
+ if (f5 (VALUE - 1) != -3)
+ __builtin_abort ();
+ if (f5 (VALUE) != -2)
+ __builtin_abort ();
+ if (f5 (VALUE + 1) != -2)
+ __builtin_abort ();
+ if (f5 (TYPE_MAX) != -2)
+ __builtin_abort ();
+
+ if (f6 (min_test) != min_test - VALUE + 2)
+ __builtin_abort ();
+ if (f6 (VALUE - 1) != 1)
+ __builtin_abort ();
+ if (f6 (VALUE) != 2)
+ __builtin_abort ();
+ if (f6 (VALUE + 1) != 2)
+ __builtin_abort ();
+ if (f6 (TYPE_MAX) != 2)
+ __builtin_abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_2.c b/gcc/testsuite/gcc.target/aarch64/min_plus_2.c
new file mode 100644
index 000000000..bc0141b72
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_2.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (x[0-9]+), x0, #?4094
+** csel x0, \1, xzr, l[te]
+** ret
+*/
+/*
+** f2:
+** subs (x[0-9]+), x0, #?4094
+** csel x0, \1, xzr, l[te]
+** ret
+*/
+/*
+** f3:
+** subs (x[0-9]+), x0, #?4093
+** csinc x0, \1, xzr, le
+** ret
+*/
+/*
+** f4:
+** subs (x[0-9]+), x0, #?4095
+** csinv x0, \1, xzr, lt
+** ret
+*/
+
+#define TYPE int64_t
+#define TYPE_MIN INT64_MIN
+#define TYPE_MAX INT64_MAX
+#define VALUE 4094
+
+#include "min_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_3.c b/gcc/testsuite/gcc.target/aarch64/min_plus_3.c
new file mode 100644
index 000000000..1808e4b0c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_3.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (w[0-9]+), w0, #?4095
+** csel w0, \1, wzr, l[te]
+** ret
+*/
+/*
+** f2:
+** subs (w[0-9]+), w0, #?4095
+** csel w0, \1, wzr, l[te]
+** ret
+*/
+/*
+** f3:
+** subs (w[0-9]+), w0, #?4094
+** csinc w0, \1, wzr, le
+** ret
+*/
+/*
+** f4:
+** subs (w[0-9]+), w0, #?4096
+** csinv w0, \1, wzr, lt
+** ret
+*/
+
+#define TYPE int32_t
+#define TYPE_MIN INT32_MIN
+#define TYPE_MAX INT32_MAX
+#define VALUE 4095
+
+#include "min_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_4.c b/gcc/testsuite/gcc.target/aarch64/min_plus_4.c
new file mode 100644
index 000000000..6c581fed6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_4.c
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (x[0-9]+), x0, #?4096
+** csel x0, \1, xzr, l[te]
+** ret
+*/
+/*
+** f2:
+** subs (x[0-9]+), x0, #?4096
+** csel x0, \1, xzr, l[te]
+** ret
+*/
+/*
+** f3:
+** subs (x[0-9]+), x0, #?4095
+** csinc x0, \1, xzr, le
+** ret
+*/
+/* f4 out of range */
+
+#define TYPE int64_t
+#define TYPE_MIN INT64_MIN
+#define TYPE_MAX INT64_MAX
+#define VALUE 4096
+
+#include "min_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_5.c b/gcc/testsuite/gcc.target/aarch64/min_plus_5.c
new file mode 100644
index 000000000..97542d507
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_5.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (w[0-9]+), w0, #?4095
+** csel w0, \1, wzr, (cc|ls)
+** ret
+*/
+/*
+** f2:
+** subs (w[0-9]+), w0, #?4095
+** csel w0, \1, wzr, (cc|ls)
+** ret
+*/
+/*
+** f3:
+** subs (w[0-9]+), w0, #?4094
+** csinc w0, \1, wzr, ls
+** ret
+*/
+/*
+** f4:
+** subs (w[0-9]+), w0, #?4096
+** csinv w0, \1, wzr, cc
+** ret
+*/
+
+#define TYPE uint32_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT32_MAX
+#define VALUE 4095
+
+#include "min_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_6.c b/gcc/testsuite/gcc.target/aarch64/min_plus_6.c
new file mode 100644
index 000000000..176533cb2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_6.c
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+
+#define TYPE uint64_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT64_MAX
+#define VALUE 1
+
+#include "min_plus_1.c"
diff --git a/gcc/testsuite/gcc.target/aarch64/min_plus_7.c b/gcc/testsuite/gcc.target/aarch64/min_plus_7.c
new file mode 100644
index 000000000..d6a217a51
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/min_plus_7.c
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** f1:
+** subs (x[0-9]+), x0, #?2
+** csel x0, \1, xzr, (cc|ls)
+** ret
+*/
+/*
+** f2:
+** subs (x[0-9]+), x0, #?2
+** csel x0, \1, xzr, (cc|ls)
+** ret
+*/
+/*
+** f3:
+** subs (x[0-9]+), x0, #?1
+** csinc x0, \1, xzr, ls
+** ret
+*/
+/*
+** f4:
+** subs (x[0-9]+), x0, #?3
+** csinv x0, \1, xzr, cc
+** ret
+*/
+
+#define TYPE uint64_t
+#define TYPE_MIN 0
+#define TYPE_MAX UINT64_MAX
+#define VALUE 2
+
+#include "min_plus_1.c"
--
2.27.0.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangding16/src-gcc.git
git@gitee.com:wangding16/src-gcc.git
wangding16
src-gcc
src-gcc
master

搜索帮助