public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: PING^5: [PATCH] rtl-optimization/110939 Really fix narrow comparison of memory and constant
Date: Fri, 29 Sep 2023 12:51:14 -0600	[thread overview]
Message-ID: <4abe5e32-0f36-4836-8fbd-ee7efb64b4de@gmail.com> (raw)
In-Reply-To: <ZQnHH+szc2+Drh+J@li-819a89cc-2401-11b2-a85c-cca1ce6aa768.ibm.com>



On 9/19/23 10:06, Stefan Schulze Frielinghaus wrote:
> Since this patch is sitting in the queue for quite some time and (more
> importantly?) solves a bootstrap problem let me reiterate:
> 
> While writing the initial commit 7cdd0860949c6c3232e6cff1d7ca37bb5234074c
> and the subsequent (potential) fix 41ef5a34161356817807be3a2e51fbdbe575ae85
> I was not aware of the fact that the normal form of a CONST_INT,
> representing an unsigned integer with fewer bits than in HOST_WIDE_INT,
> is a sign-extended version of the unsigned integer.  This invariant is
> checked in rtl.h where we have at line 2297:
> 
>      case CONST_INT:
>        if (precision < HOST_BITS_PER_WIDE_INT)
>          /* Nonzero BImodes are stored as STORE_FLAG_VALUE, which on many
>             targets is 1 rather than -1.  */
>          gcc_checking_assert (INTVAL (x.first)
>                               == sext_hwi (INTVAL (x.first), precision)
>                               || (x.second == BImode && INTVAL (x.first) == 1));
> 
> This was pretty surprising and frankly speaking unintuitive to me which

At the heart of the matter (as I think Eric recently mentioned) is that 
CONST_INT objects do not have a mode.  So consider something like 
(const_int 32768) on a 32bit host.

In modes wider than HImode is does exactly what you'd expect.  But if 
you tried to use it in a HImode context, then it's actually invalid as 
it needs to be sign extended resulting in (const_int -32768).  That's 
what gen_int_mode handles for you -- you provide a mode for the context 
in which the constant will be used and you get back suitable RTL.

This actually mimicks what some targets do in hardware for 32 bit 
objects being held in 64bit registers.

Anyway, that's the background.  It is highly likely there are bugs where 
we fail to use gen_int_mode when we should or in some tests for when an 
optimization may or may not be applicable.  So I wouldn't be surprised 
at all if you were to grub around and find cases that aren't properly 
handled -- particularly of the missed-optimization variety.


>
> 
> Independent of why such a normal form was chosen, this patch restores
> the normal form and solves the bootstrap problem for Loongarch.
Digging it out and looking at it momentarily.  It just keep falling off 
the end of the TODO list day-to-day.  Sorry for that, particularly since 
you're probably getting bugged by folks looking to restore builds/test 
results.

jeff

  parent reply	other threads:[~2023-09-29 18:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 13:04 Stefan Schulze Frielinghaus
2023-08-12  1:04 ` Xi Ruoyao
2023-08-14  6:39   ` Stefan Schulze Frielinghaus
2023-08-18 11:04 ` Stefan Schulze Frielinghaus
2023-08-24  3:31   ` PING^2: " Xi Ruoyao
2023-09-04  5:55     ` PING^3: " Stefan Schulze Frielinghaus
2023-09-10 16:56       ` PING^4: " Xi Ruoyao
2023-09-19  7:31         ` PING^5: " Xi Ruoyao
2023-09-19 16:06           ` Stefan Schulze Frielinghaus
2023-09-25 10:52             ` Eric Botcazou
2023-09-29 18:51             ` Jeff Law [this message]
2023-08-29 10:24 ` Xi Ruoyao
2023-09-29 19:01 ` Jeff Law
2023-10-01 14:26   ` Stefan Schulze Frielinghaus
2023-10-01 14:36     ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4abe5e32-0f36-4836-8fbd-ee7efb64b4de@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=stefansf@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).