public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison.
@ 2005-05-18 12:32 dwmw2 at infradead dot org
  2005-05-18 12:33 ` [Bug rtl-optimization/21643] " dwmw2 at infradead dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dwmw2 at infradead dot org @ 2005-05-18 12:32 UTC (permalink / raw)
  To: gcc-bugs

I'd expect the result of compiling these two functions to be identical, but it
isn't:

int fish1(unsigned char c)
{
        if (c =='"' || c == 0x20 || c < 0x20)
                return 1;
}
int fish2(unsigned char c)
{
        if (c == '"' || c <= 0x20)
                return 1;
}

If I remove the 'c == '"' ||' from each, I do get the expected results.
$ gcc -O2 -S asd.c -o /dev/stdout
        .file   "asd.c"
        .section        ".text"
        .align 2
        .p2align 4,,15
        .globl fish1
        .type   fish1, @function
fish1:
        mr 0,3
        li 3,1
        cmpwi 7,0,34
        cmpwi 6,0,32
        beqlr 7
        cmplwi 7,0,31
        beqlr 6
        blelr 7
        blr
        .size   fish1,.-fish1
        .align 2
        .p2align 4,,15
        .globl fish2
        .type   fish2, @function
fish2:
        mr 0,3
        li 3,1
        cmpwi 7,0,34
        cmplwi 6,0,32
        beqlr 7
        blelr 6
        blr
        .size   fish2,.-fish2
        .ident  "GCC: (GNU) 4.0.0 20050512 (Red Hat 4.0.0-5)"
        .section        .note.GNU-stack,"",@progbits

-- 
           Summary: GCC fails to merge ranges in comparison.
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dwmw2 at infradead dot org
                CC: gcc-bugs at gcc dot gnu dot org,jakub at redhat dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21643


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/21643] GCC fails to merge ranges in comparison.
  2005-05-18 12:32 [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison dwmw2 at infradead dot org
@ 2005-05-18 12:33 ` dwmw2 at infradead dot org
  2005-05-18 12:39 ` [Bug tree-optimization/21643] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: dwmw2 at infradead dot org @ 2005-05-18 12:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dwmw2 at infradead dot org  2005-05-18 12:33 -------
Happens with gcc 3.4 too, and also on i386.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21643


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/21643] GCC fails to merge ranges in comparison.
  2005-05-18 12:32 [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison dwmw2 at infradead dot org
  2005-05-18 12:33 ` [Bug rtl-optimization/21643] " dwmw2 at infradead dot org
@ 2005-05-18 12:39 ` pinskia at gcc dot gnu dot org
  2005-05-18 17:21 ` trt at acm dot org
  2005-05-18 17:28 ` trt at acm dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-18 12:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-18 12:38 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
          Component|rtl-optimization            |tree-optimization
     Ever Confirmed|                            |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-18 12:38:44
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21643


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/21643] GCC fails to merge ranges in comparison.
  2005-05-18 12:32 [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison dwmw2 at infradead dot org
  2005-05-18 12:33 ` [Bug rtl-optimization/21643] " dwmw2 at infradead dot org
  2005-05-18 12:39 ` [Bug tree-optimization/21643] " pinskia at gcc dot gnu dot org
@ 2005-05-18 17:21 ` trt at acm dot org
  2005-05-18 17:28 ` trt at acm dot org
  3 siblings, 0 replies; 5+ messages in thread
From: trt at acm dot org @ 2005-05-18 17:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2005-05-18 17:21 -------
This is because fold-const.c only does ad-hoc re-association.
Here is an example for fold_truthop (approx line 8805)

      /* Check for the possibility of merging component references.  If our
         lhs is another similar operation, try to merge its rhs with our
         rhs.  Then try to merge our lhs and rhs.  */
      if (TREE_CODE (arg0) == code
          && 0 != (tem = fold_truthop (code, type,
                                       TREE_OPERAND (arg0, 1), arg1)))
        return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem);

A similar hack could be done for fold_range_test.

(I wrote a helper fold_assoc (f, x, code, type, op1, op2) that does this in a
more general way, but it in turn needed `find_assoc_p' and `commutes_p'
functions, and handling EXPR_MINUS was onerous.  It might be too slow for
general use.  Basically, it needs a fast way to check for common subexpressions
to avoid pointless recursions.)

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21643


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/21643] GCC fails to merge ranges in comparison.
  2005-05-18 12:32 [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison dwmw2 at infradead dot org
                   ` (2 preceding siblings ...)
  2005-05-18 17:21 ` trt at acm dot org
@ 2005-05-18 17:28 ` trt at acm dot org
  3 siblings, 0 replies; 5+ messages in thread
From: trt at acm dot org @ 2005-05-18 17:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2005-05-18 17:28 -------
Here is a equivalent case that gcc also misses (but beyond scope of
fold-const.c). By the way, since there is a missing final return, can't gcc just
simplify all three functions into "return 1;" :-)

int fish3(unsigned char c)
{
        if (c =='"') return 1;
        if (c == 0x20) return 1;
        if (c < 0x20) return 1;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21643


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-18 17:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-18 12:32 [Bug rtl-optimization/21643] New: GCC fails to merge ranges in comparison dwmw2 at infradead dot org
2005-05-18 12:33 ` [Bug rtl-optimization/21643] " dwmw2 at infradead dot org
2005-05-18 12:39 ` [Bug tree-optimization/21643] " pinskia at gcc dot gnu dot org
2005-05-18 17:21 ` trt at acm dot org
2005-05-18 17:28 ` trt at acm dot org

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).