public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/46265] New: Missing ifcvt
@ 2010-11-02  0:37 xinliangli at gmail dot com
  2010-11-02 10:24 ` [Bug rtl-optimization/46265] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2010-11-02  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Missing ifcvt
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: xinliangli@gmail.com


Compile the following code with -O2

int *gp;
int g, g2;
int foo(int p)
{
   int t = 0;
   if (p)
      t = *gp + 1;       

   return (*gp + t);
}


Trunk gcc produces:


    movq    gp(%rip), %rax
    xorl    %edx, %edx
    movl    (%rax), %eax
    testl    %edi, %edi
    je    .L3
    leal    1(%rax), %edx
.L3:
    addl    %edx, %eax
    ret


llvm (with clang) produces:


    movq    gp(%rip), %rax
    movl    (%rax), %ecx
    leal    1(%rcx), %edx
    testl    %edi, %edi
    movl    $0, %eax
    cmovnel    %edx, %eax
    addl    %ecx, %eax
    ret


Gcc's ifcvt seems weak. If changing t=*gp + 1 to t = g then the assignment can
be ifcvted by gcc.

David


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

* [Bug rtl-optimization/46265] Missing ifcvt
  2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
@ 2010-11-02 10:24 ` rguenth at gcc dot gnu.org
  2010-11-03  5:25 ` davidxl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-02 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.11.02 10:24:04
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-11-02 10:24:04 UTC ---
Well, PRE manages to not optimize the addition because of the missing
availability of *gp in BB2 (the dataflow equations don't include hoisting,
a long standing problem).  Ideally PRE already would transform it to

  tem = *gp;
  if (p)
    return tem + tem + 1
  else
    return tem;


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

* [Bug rtl-optimization/46265] Missing ifcvt
  2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
  2010-11-02 10:24 ` [Bug rtl-optimization/46265] " rguenth at gcc dot gnu.org
@ 2010-11-03  5:25 ` davidxl at gcc dot gnu.org
  2010-11-03  5:59 ` davidxl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: davidxl at gcc dot gnu.org @ 2010-11-03  5:25 UTC (permalink / raw)
  To: gcc-bugs

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

davidxl <davidxl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidxl at gcc dot gnu.org

--- Comment #2 from davidxl <davidxl at gcc dot gnu.org> 2010-11-03 05:24:54 UTC ---
The following is another example gcc fails to ifcvt, while llvm performs ifcvt
+ hoist the conditional assignment out of the loop.

 2 extern int gen_int(int);
  3 extern void ref_int_p(int*);
  4 
  5 void kernel3 ()
  6 {
  7   int i;
  8   int j;
  9   int k;
 10   int l;
 11   int m;
 12   int a[200];
 13 
 14   j = gen_int (0);
 15   k = gen_int (0);
 16   l = gen_int (0);
 17   m = gen_int (0);
 18 
 19   for (i = 0; i < 200; i++)
 20     {
 21       if (j < k || j < l || j < m ) 
 22         a[i] = 1;
 23       else
 24         a[i] = j;
 25     }
 26 
 27   ref_int_p (&a[0]);
 28 
 29   return;
 30 }


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

* [Bug rtl-optimization/46265] Missing ifcvt
  2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
  2010-11-02 10:24 ` [Bug rtl-optimization/46265] " rguenth at gcc dot gnu.org
  2010-11-03  5:25 ` davidxl at gcc dot gnu.org
@ 2010-11-03  5:59 ` davidxl at gcc dot gnu.org
  2010-11-04  0:55 ` xinliangli at gmail dot com
  2021-11-21  7:21 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: davidxl at gcc dot gnu.org @ 2010-11-03  5:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from davidxl <davidxl at gcc dot gnu.org> 2010-11-03 05:59:30 UTC ---
Another example gcc fails to ifcvt (succeeds only if only one statement is in
if and else block.

void ref_int_p(int *); 

void foo (int j, int k)
{
  int i;
  int a[200], b[100];
  i = 0;
  for ( ; i < 100; i++)
  {
    if (j < k)
      {   
        a[i] = j;
        b[i] = j;
      }   
      else
      {   
        a[i] = 1;
        b[i] = 1;
      }   
 }
  ref_int_p (&a[0]);
  ref_int_p (&b[0]);

  return;
}

It (the loop) should be generated like:

LBB0_1:
        cmpl    %esi, %edi
        movl    $1, %ecx
        cmovll  %edi, %ecx
        movl    %ecx, -800(%rbp,%rax,4)
        movl    %ecx, -1200(%rbp,%rax,4)
        incq    %rax
        cmpq    $100, %rax
        jne     .LBB0_1

David


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

* [Bug rtl-optimization/46265] Missing ifcvt
  2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
                   ` (2 preceding siblings ...)
  2010-11-03  5:59 ` davidxl at gcc dot gnu.org
@ 2010-11-04  0:55 ` xinliangli at gmail dot com
  2021-11-21  7:21 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2010-11-04  0:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from davidxl <xinliangli at gmail dot com> 2010-11-04 00:55:35 UTC ---

Another case that needs to be handled (none of the compiler tested handle it)

For ifcvt to happen, control flow needs to be simplified (for case of
if-then-else if ..) this is possible when the conditions tested are exclusive.
Some cost heuristics needs to be developed, as the transformation makes the
second cmp to be done unconditionally. In the following example, ifcvt does not
happen for function foo, but for foo2.

int  foo (int i,  int j, int t)
{
   int r1 = 0, r2 = 0;
   if (i > j)
   {
     r1 = t + 1;
   }
   else if (i == j)
   {
      r2 = t + 3;
   }

   return r1+r2;
}

int  foo2 (int i,  int j, int t)
{
   int r1 = 0, r2 = 0;
   if (i > j)
   {
     r1 = t + 1;
   }

   if (i == j)
   {
      r2 = t + 3;
   }

   return r1+r2;
}


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

* [Bug rtl-optimization/46265] Missing ifcvt
  2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
                   ` (3 preceding siblings ...)
  2010-11-04  0:55 ` xinliangli at gmail dot com
@ 2021-11-21  7:21 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-21  7:21 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|7.1.0                       |
   Target Milestone|---                         |11.0
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The original testcase in comment #0 was fixed for GCC 7 by r7-1935.

The one in comment #2 was fixed for GCC 8 I think by r8-7372.

The one in comment #3 was fixed for GCC 11 by some patches to
tree-ssa-loop-im.c (I cannot figure out right now).

The one in comment #4 was fixed for GCC 6 by a few changes to ifcvt.c

So I am just going to close this as fixed since all testcases are fixed.

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

end of thread, other threads:[~2021-11-21  7:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-02  0:37 [Bug rtl-optimization/46265] New: Missing ifcvt xinliangli at gmail dot com
2010-11-02 10:24 ` [Bug rtl-optimization/46265] " rguenth at gcc dot gnu.org
2010-11-03  5:25 ` davidxl at gcc dot gnu.org
2010-11-03  5:59 ` davidxl at gcc dot gnu.org
2010-11-04  0:55 ` xinliangli at gmail dot com
2021-11-21  7:21 ` pinskia at gcc dot gnu.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).