[Bug tree-optimization/108397] New: Missed optimization with [0, 0][-1U,-1U] range arithmetics

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 13 16:52:09 GMT 2023


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

            Bug ID: 108397
           Summary: Missed optimization with [0, 0][-1U,-1U] range
                    arithmetics
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: hjl.tools at gmail dot com, jakub at gcc dot gnu.org,
                    marxin at gcc dot gnu.org, rguenth at gcc dot gnu.org,
                    unassigned at gcc dot gnu.org, uros at gcc dot gnu.org,
                    yinyuefengyi at gmail dot com, zsojka at seznam dot cz
        Depends on: 107131
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

+++ This bug was initially created as a clone of Bug #107131 +++

__attribute__((noipa)) unsigned long long                                       
foo (unsigned char o)                                                           
{                                                                               
  unsigned long long t1 = -(long long) (o == 0);                                
  unsigned long long t2 = -(long long) (t1 > 10439075533421201520ULL);          
  unsigned long long t3 = -(long long) (t1 <= t2);                              
  return t3;                                                                    
}                                                                               

from comment 8 of that PR could be optimized into return -1ULL.
t1 has range [0,0][-1ULL,-1ULL], t2 is set to 0 if t1 is 0 and to -1ULL if t1
is -1ULL
and thus t2 could be optimized to t2 = t1.  And t1 <= t2 can then trivially
fold to
t1 <= t1 aka true.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107131
[Bug 107131] [11/12 Regression] wrong code with -Os -fno-ipa-vrp
-fno-tree-bit-ccp


More information about the Gcc-bugs mailing list