public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/97960] [8/9/10 Regression] Wrong code at -O3 since r8-6511-g3ae129323d
Date: Tue, 02 Feb 2021 09:35:23 +0000	[thread overview]
Message-ID: <bug-97960-4-iFPzicWhk2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97960-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97960

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[8/9/10/11 Regression]      |[8/9/10 Regression] Wrong
                   |Wrong code at -O3 since     |code at -O3 since
                   |r8-6511-g3ae129323d         |r8-6511-g3ae129323d

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk by

https://gcc.gnu.org/g:4cf70c20cb10acd6fb1016611d05540728176b60                  

commit r11-5904-g4cf70c20cb10acd6fb1016611d05540728176b60                       
Author: Richard Sandiford <richard.sandiford@arm.com>                           
Date:   Thu Dec 10 12:10:00 2020 +0000                                          

    data-ref: Rework integer handling in split_constant_offset [PR98069]        

    PR98069 is about a case in which split_constant_offset miscategorises       
    an expression of the form:                                                  

      int foo;                                                                  
      …                                                                         
      POINTER_PLUS_EXPR<base, (sizetype)(INT_MIN - foo) * size>                 

    as:                                                                         

      base: base                                                                
      offset: (sizetype) (-foo) * size                                          
      init: INT_MIN * size                                                      

    “-foo” overflows when “foo” is INT_MIN, whereas the original expression     
    didn't overflow in that case.                                               

    As discussed in the PR trail, we could simply ignore the fact that          
    int overflow is undefined and treat it as a wrapping type, but that         
    is likely to pessimise quite a few cases.                                   

    This patch instead reworks split_constant_offset so that:                   

    - it treats integer operations as having an implicit cast to sizetype       
    - for integer operations, the returned VAR has type sizetype                

    In other words, the problem becomes to express:                             

      (sizetype) (OP0 CODE OP1)                                                 

    as:                                                                         

      VAR:sizetype + (sizetype) OFF:ssizetype                                   

    The top-level integer split_constant_offset will (usually) be a sizetype    
    POINTER_PLUS operand, so the extra cast to sizetype disappears.  But adding 
    the cast allows the conversion handling to defer a lot of the difficult     
    cases to the recursive split_constant_offset call, which can detect         
    overflow on individual operations.                                          

    The net effect is to analyse the access above as:                           

      base: base                                                                
      offset: -(sizetype) foo * size                                            
      init: INT_MIN * size                                                      

    See the comments in the patch for more details.                             

    gcc/                                                                        
            PR tree-optimization/98069                                          
            * tree-data-ref.c (compute_distributive_range): New function.       
            (nop_conversion_for_offset_p): Likewise.                            
            (split_constant_offset): In the internal overload, treat integer    
            expressions as having an implicit cast to sizetype and express      
            them accordingly.  Pass back the range of the original (uncast)     
            expression in a new range parameter.                                
            (split_constant_offset_1): Likewise.  Rework the handling of        
            conversions to account for the implicit sizetype casts.

  parent reply	other threads:[~2021-02-02  9:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 17:13 [Bug tree-optimization/97960] New: [8/9/10/11 " acoplan at gcc dot gnu.org
2020-11-23 17:53 ` [Bug tree-optimization/97960] " acoplan at gcc dot gnu.org
2020-11-23 17:55 ` marxin at gcc dot gnu.org
2020-11-24  8:20 ` rguenth at gcc dot gnu.org
2020-11-24 15:12 ` rguenth at gcc dot gnu.org
2020-11-24 15:29 ` rsandifo at gcc dot gnu.org
2021-01-21 11:59 ` jakub at gcc dot gnu.org
2021-01-22  8:01 ` rguenth at gcc dot gnu.org
2021-01-22  9:27 ` acoplan at gcc dot gnu.org
2021-02-01 16:53 ` jakub at gcc dot gnu.org
2021-02-02  9:03 ` cvs-commit at gcc dot gnu.org
2021-02-02  9:35 ` jakub at gcc dot gnu.org [this message]
2021-04-22 13:27 ` [Bug tree-optimization/97960] [8/9/10 " rsandifo at gcc dot gnu.org
2021-04-23  9:21 ` rsandifo at gcc dot gnu.org

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=bug-97960-4-iFPzicWhk2@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).