* [PATCH] haifa-sched: fix autopref_rank_for_schedule comparator [PR109187]
@ 2023-03-28 13:11 Alexander Monakov
2023-03-28 13:26 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Monakov @ 2023-03-28 13:11 UTC (permalink / raw)
To: gcc-patches; +Cc: Alexander Monakov
Do not attempt to use a plain subtraction for generating a three-way
comparison result in autopref_rank_for_schedule qsort comparator, as
offsets are not restricted and subtraction may overflow. Open-code
a safe three-way comparison instead.
gcc/ChangeLog:
PR rtl-optimization/109187
* haifa-sched.cc (autopref_rank_for_schedule): Avoid use of overflowing
subtraction in three-way comparison.
gcc/testsuite/ChangeLog:
PR rtl-optimization/109187
* gcc.dg/pr109187.c: New test.
---
I think I can commit this as obvious if no comment in a day, but explicit ack
is always appreciated.
Alexander
gcc/haifa-sched.cc | 2 +-
gcc/testsuite/gcc.dg/pr109187.c | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr109187.c
diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc
index 4efaa9445..e11cc5c35 100644
--- a/gcc/haifa-sched.cc
+++ b/gcc/haifa-sched.cc
@@ -5686,7 +5686,7 @@ autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2)
if (!irrel1 && !irrel2)
/* Sort memory references from lowest offset to the largest. */
- r = data1->offset - data2->offset;
+ r = (data1->offset > data2->offset) - (data1->offset < data2->offset);
else if (write)
/* Schedule "irrelevant" insns before memory stores to resolve
as many producer dependencies of stores as possible. */
diff --git a/gcc/testsuite/gcc.dg/pr109187.c b/gcc/testsuite/gcc.dg/pr109187.c
new file mode 100644
index 000000000..1ef14a73d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109187.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 --param sched-autopref-queue-depth=1" } */
+
+void f(int *a)
+{
+ for (;;)
+ asm("" :: "r"(a[-0x10000000]), "r"(a[0x10000000]), "r"(a[0]) : "memory");
+}
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] haifa-sched: fix autopref_rank_for_schedule comparator [PR109187]
2023-03-28 13:11 [PATCH] haifa-sched: fix autopref_rank_for_schedule comparator [PR109187] Alexander Monakov
@ 2023-03-28 13:26 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-28 13:26 UTC (permalink / raw)
To: Alexander Monakov; +Cc: gcc-patches
On Tue, Mar 28, 2023 at 3:11 PM Alexander Monakov via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Do not attempt to use a plain subtraction for generating a three-way
> comparison result in autopref_rank_for_schedule qsort comparator, as
> offsets are not restricted and subtraction may overflow. Open-code
> a safe three-way comparison instead.
OK.
> gcc/ChangeLog:
>
> PR rtl-optimization/109187
> * haifa-sched.cc (autopref_rank_for_schedule): Avoid use of overflowing
> subtraction in three-way comparison.
>
> gcc/testsuite/ChangeLog:
>
> PR rtl-optimization/109187
> * gcc.dg/pr109187.c: New test.
> ---
>
> I think I can commit this as obvious if no comment in a day, but explicit ack
> is always appreciated.
>
> Alexander
>
> gcc/haifa-sched.cc | 2 +-
> gcc/testsuite/gcc.dg/pr109187.c | 8 ++++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.dg/pr109187.c
>
> diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc
> index 4efaa9445..e11cc5c35 100644
> --- a/gcc/haifa-sched.cc
> +++ b/gcc/haifa-sched.cc
> @@ -5686,7 +5686,7 @@ autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2)
>
> if (!irrel1 && !irrel2)
> /* Sort memory references from lowest offset to the largest. */
> - r = data1->offset - data2->offset;
> + r = (data1->offset > data2->offset) - (data1->offset < data2->offset);
> else if (write)
> /* Schedule "irrelevant" insns before memory stores to resolve
> as many producer dependencies of stores as possible. */
> diff --git a/gcc/testsuite/gcc.dg/pr109187.c b/gcc/testsuite/gcc.dg/pr109187.c
> new file mode 100644
> index 000000000..1ef14a73d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr109187.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 --param sched-autopref-queue-depth=1" } */
> +
> +void f(int *a)
> +{
> + for (;;)
> + asm("" :: "r"(a[-0x10000000]), "r"(a[0x10000000]), "r"(a[0]) : "memory");
> +}
> --
> 2.39.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-28 13:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 13:11 [PATCH] haifa-sched: fix autopref_rank_for_schedule comparator [PR109187] Alexander Monakov
2023-03-28 13:26 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).