* [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010]
@ 2024-02-27 0:17 Greg McGary
2024-02-27 15:26 ` Greg McGary
2024-03-01 4:30 ` Jeff Law
0 siblings, 2 replies; 6+ messages in thread
From: Greg McGary @ 2024-02-27 0:17 UTC (permalink / raw)
To: gcc-patches; +Cc: Greg McGary
The sign-bit-copies of a sign-extending load cannot be known until runtime on
WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM
load. See the fix for PR112758.
2024-02-22 Greg McGary <gkm@rivosinc.com>
PR rtl-optimization/113010
* combine.cc (simplify_comparison): Simplify a SUBREG on
WORD_REGISTER_OPERATIONS targets only if it is a zero-extending
MEM load.
* gcc.c-torture/execute/pr113010.c: New test.
---
gcc/combine.cc | 15 +++++++++++++--
gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c
diff --git a/gcc/combine.cc b/gcc/combine.cc
index 76543d85b7c..b09200d757e 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -12550,9 +12550,20 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
}
/* If the inner mode is narrower and we are extracting the low part,
- we can treat the SUBREG as if it were a ZERO_EXTEND. */
+ we can treat the SUBREG as if it were a ZERO_EXTEND ... */
if (paradoxical_subreg_p (op0))
- ;
+ {
+ if (WORD_REGISTER_OPERATIONS
+ && GET_MODE_PRECISION (inner_mode) < BITS_PER_WORD
+ /* On WORD_REGISTER_OPERATIONS targets the bits
+ beyond sub_mode aren't considered undefined,
+ so optimize only if it is a MEM load when MEM loads
+ zero extend, because then the upper bits are all zero. */
+ && !(MEM_P (SUBREG_REG (op0))
+ && load_extend_op (inner_mode) == ZERO_EXTEND))
+ break;
+ /* FALLTHROUGH to case ZERO_EXTEND */
+ }
else if (subreg_lowpart_p (op0)
&& GET_MODE_CLASS (mode) == MODE_INT
&& is_int_mode (GET_MODE (SUBREG_REG (op0)), &inner_mode)
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113010.c b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
new file mode 100644
index 00000000000..a95c613c1df
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
@@ -0,0 +1,9 @@
+int minus_1 = -1;
+
+int
+main ()
+{
+ if ((0, 0xfffffffful) >= minus_1)
+ __builtin_abort ();
+ return 0;
+}
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010]
2024-02-27 0:17 [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010] Greg McGary
@ 2024-02-27 15:26 ` Greg McGary
2024-03-01 4:30 ` Jeff Law
1 sibling, 0 replies; 6+ messages in thread
From: Greg McGary @ 2024-02-27 15:26 UTC (permalink / raw)
To: Greg McGary; +Cc: gcc-patches
On 2/26/24 5:17 PM, Greg McGary wrote:
> diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113010.c b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
> new file mode 100644
> index 00000000000..a95c613c1df
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
> @@ -0,0 +1,9 @@
> +int minus_1 = -1;
> +
> +int
> +main ()
> +{
> + if ((0, 0xfffffffful) >= minus_1)
> + __builtin_abort ();
> + return 0;
> +}
Note that this is a stale version of the testcase. The constant needs to be
long long 0xffffffffull for the sake of 32-bit machines, such as ARM.
G
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010]
2024-02-27 0:17 [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010] Greg McGary
2024-02-27 15:26 ` Greg McGary
@ 2024-03-01 4:30 ` Jeff Law
2024-03-04 16:18 ` Rainer Orth
1 sibling, 1 reply; 6+ messages in thread
From: Jeff Law @ 2024-03-01 4:30 UTC (permalink / raw)
To: Greg McGary, gcc-patches
On 2/26/24 17:17, Greg McGary wrote:
> The sign-bit-copies of a sign-extending load cannot be known until runtime on
> WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM
> load. See the fix for PR112758.
>
> 2024-02-22 Greg McGary <gkm@rivosinc.com>
>
> PR rtl-optimization/113010
> * combine.cc (simplify_comparison): Simplify a SUBREG on
> WORD_REGISTER_OPERATIONS targets only if it is a zero-extending
> MEM load.
>
> * gcc.c-torture/execute/pr113010.c: New test.
I think this is fine for the trunk. I'll do some final testing on it
tomorrow.
Jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010]
2024-03-01 4:30 ` Jeff Law
@ 2024-03-04 16:18 ` Rainer Orth
2024-03-04 16:49 ` [PATCH] combine: Fix recent WORD_REGISTER_OPERATIONS check [PR113010] Jakub Jelinek
0 siblings, 1 reply; 6+ messages in thread
From: Rainer Orth @ 2024-03-04 16:18 UTC (permalink / raw)
To: Jeff Law; +Cc: Greg McGary, gcc-patches
Hi Jeff,
> On 2/26/24 17:17, Greg McGary wrote:
>> The sign-bit-copies of a sign-extending load cannot be known until runtime on
>> WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM
>> load. See the fix for PR112758.
>> 2024-02-22 Greg McGary <gkm@rivosinc.com>
>> PR rtl-optimization/113010
>> * combine.cc (simplify_comparison): Simplify a SUBREG on
>> WORD_REGISTER_OPERATIONS targets only if it is a zero-extending
>> MEM load.
>> * gcc.c-torture/execute/pr113010.c: New test.
> I think this is fine for the trunk. I'll do some final testing on it
> tomorrow.
unfortunately, the patch broke Solaris/SPARC bootstrap
(sparc-sun-solaris2.11):
/vol/gcc/src/hg/master/local/gcc/combine.cc: In function 'rtx_code simplify_comparison(rtx_code, rtx_def**, rtx_def**)':
/vol/gcc/src/hg/master/local/gcc/combine.cc:12101:25: error: '*(unsigned int*)((char*)&inner_mode + offsetof(scalar_int_mode, scalar_int_mode::m_mode))' may be used uninitialized [-Werror=maybe-uninitialized]
12101 | scalar_int_mode mode, inner_mode, tmode;
| ^~~~~~~~~~
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] combine: Fix recent WORD_REGISTER_OPERATIONS check [PR113010]
2024-03-04 16:18 ` Rainer Orth
@ 2024-03-04 16:49 ` Jakub Jelinek
2024-03-04 17:59 ` Jeff Law
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2024-03-04 16:49 UTC (permalink / raw)
To: Jeff Law, Rainer Orth; +Cc: Greg McGary, gcc-patches
On Mon, Mar 04, 2024 at 05:18:39PM +0100, Rainer Orth wrote:
> > On 2/26/24 17:17, Greg McGary wrote:
> >> The sign-bit-copies of a sign-extending load cannot be known until runtime on
> >> WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM
> >> load. See the fix for PR112758.
> >> 2024-02-22 Greg McGary <gkm@rivosinc.com>
> >> PR rtl-optimization/113010
> >> * combine.cc (simplify_comparison): Simplify a SUBREG on
> >> WORD_REGISTER_OPERATIONS targets only if it is a zero-extending
> >> MEM load.
> >> * gcc.c-torture/execute/pr113010.c: New test.
> > I think this is fine for the trunk. I'll do some final testing on it
> > tomorrow.
>
> unfortunately, the patch broke Solaris/SPARC bootstrap
> (sparc-sun-solaris2.11):
>
> /vol/gcc/src/hg/master/local/gcc/combine.cc: In function 'rtx_code simplify_comparison(rtx_code, rtx_def**, rtx_def**)':
> /vol/gcc/src/hg/master/local/gcc/combine.cc:12101:25: error: '*(unsigned int*)((char*)&inner_mode + offsetof(scalar_int_mode, scalar_int_mode::m_mode))' may be used uninitialized [-Werror=maybe-uninitialized]
> 12101 | scalar_int_mode mode, inner_mode, tmode;
> | ^~~~~~~~~~
I don't see how it could ever work properly, inner_mode in that spot is
just uninitialized.
I think we shouldn't worry about paradoxical subregs of non-scalar_int_mode
REGs/MEMs and for the scalar_int_mode ones should initialize inner_mode
before we use it.
Another option would be to use
maybe_lt (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (op0))), BITS_PER_WORD)
and
load_extend_op (GET_MODE (SUBREG_REG (op0))) == ZERO_EXTEND,
or set machine_mode smode = GET_MODE (SUBREG_REG (op0)); and use it in
those two spots.
2024-03-04 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/113010
* combine.cc (simplify_comparison): Guard the
WORD_REGISTER_OPERATIONS check on scalar_int_mode of SUBREG_REG
and initialize inner_mode.
--- gcc/combine.cc.jj 2024-03-04 10:01:21.054937316 +0100
+++ gcc/combine.cc 2024-03-04 17:40:51.556052647 +0100
@@ -12554,6 +12554,8 @@ simplify_comparison (enum rtx_code code,
if (paradoxical_subreg_p (op0))
{
if (WORD_REGISTER_OPERATIONS
+ && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (op0)),
+ &inner_mode)
&& GET_MODE_PRECISION (inner_mode) < BITS_PER_WORD
/* On WORD_REGISTER_OPERATIONS targets the bits
beyond sub_mode aren't considered undefined,
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] combine: Fix recent WORD_REGISTER_OPERATIONS check [PR113010]
2024-03-04 16:49 ` [PATCH] combine: Fix recent WORD_REGISTER_OPERATIONS check [PR113010] Jakub Jelinek
@ 2024-03-04 17:59 ` Jeff Law
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Law @ 2024-03-04 17:59 UTC (permalink / raw)
To: Jakub Jelinek, Rainer Orth; +Cc: Greg McGary, gcc-patches
On 3/4/24 09:49, Jakub Jelinek wrote:
> On Mon, Mar 04, 2024 at 05:18:39PM +0100, Rainer Orth wrote:
>>> On 2/26/24 17:17, Greg McGary wrote:
>>>> The sign-bit-copies of a sign-extending load cannot be known until runtime on
>>>> WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM
>>>> load. See the fix for PR112758.
>>>> 2024-02-22 Greg McGary <gkm@rivosinc.com>
>>>> PR rtl-optimization/113010
>>>> * combine.cc (simplify_comparison): Simplify a SUBREG on
>>>> WORD_REGISTER_OPERATIONS targets only if it is a zero-extending
>>>> MEM load.
>>>> * gcc.c-torture/execute/pr113010.c: New test.
>>> I think this is fine for the trunk. I'll do some final testing on it
>>> tomorrow.
>>
>> unfortunately, the patch broke Solaris/SPARC bootstrap
>> (sparc-sun-solaris2.11):
>>
>> /vol/gcc/src/hg/master/local/gcc/combine.cc: In function 'rtx_code simplify_comparison(rtx_code, rtx_def**, rtx_def**)':
>> /vol/gcc/src/hg/master/local/gcc/combine.cc:12101:25: error: '*(unsigned int*)((char*)&inner_mode + offsetof(scalar_int_mode, scalar_int_mode::m_mode))' may be used uninitialized [-Werror=maybe-uninitialized]
>> 12101 | scalar_int_mode mode, inner_mode, tmode;
>> | ^~~~~~~~~~
>
> I don't see how it could ever work properly, inner_mode in that spot is
> just uninitialized.
>
> I think we shouldn't worry about paradoxical subregs of non-scalar_int_mode
> REGs/MEMs and for the scalar_int_mode ones should initialize inner_mode
> before we use it.
> Another option would be to use
> maybe_lt (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (op0))), BITS_PER_WORD)
> and
> load_extend_op (GET_MODE (SUBREG_REG (op0))) == ZERO_EXTEND,
> or set machine_mode smode = GET_MODE (SUBREG_REG (op0)); and use it in
> those two spots.
>
> 2024-03-04 Jakub Jelinek <jakub@redhat.com>
>
> PR rtl-optimization/113010
> * combine.cc (simplify_comparison): Guard the
> WORD_REGISTER_OPERATIONS check on scalar_int_mode of SUBREG_REG
> and initialize inner_mode.
Egad. Sorry. OK for the trunk. Thanks for picking this up. Got
distracted by an internal issue.
jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-03-04 18:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 0:17 [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010] Greg McGary
2024-02-27 15:26 ` Greg McGary
2024-03-01 4:30 ` Jeff Law
2024-03-04 16:18 ` Rainer Orth
2024-03-04 16:49 ` [PATCH] combine: Fix recent WORD_REGISTER_OPERATIONS check [PR113010] Jakub Jelinek
2024-03-04 17:59 ` Jeff Law
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).