public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100449] New: Unrolled loop ignores __building_constant_p
@ 2021-05-06 12:38 christophe.leroy at csgroup dot eu
  2021-05-07  7:02 ` [Bug c/100449] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: christophe.leroy at csgroup dot eu @ 2021-05-06 12:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100449
           Summary: Unrolled loop ignores __building_constant_p
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.leroy at csgroup dot eu
  Target Milestone: ---

The following code built with -m32 -O2 -c :

static inline void mtsr(unsigned long val, unsigned long idx)
{
        if (__builtin_constant_p(idx))
                asm volatile("mtsr %1, %0" : : "r" (val), "i" (idx >> 28));
        else
                asm volatile("mtsrin %0, %1" : : "r" (val), "r" (idx));
}

void update_user_segments(unsigned long val)
{
        int i;

        for (i = 0; i < 4; i++)
                mtsr(val + 0x111 * i, i << 28);
}

Results in:

00000000 <update_user_segments>:
   0:   39 20 00 00     li      r9,0
   4:   7c 60 49 e4     mtsrin  r3,r9
   8:   3d 40 10 00     lis     r10,4096
   c:   39 23 01 11     addi    r9,r3,273
  10:   7d 20 51 e4     mtsrin  r9,r10
  14:   3d 40 20 00     lis     r10,8192
  18:   39 23 02 22     addi    r9,r3,546
  1c:   7d 20 51 e4     mtsrin  r9,r10
  20:   3d 20 30 00     lis     r9,12288
  24:   38 63 03 33     addi    r3,r3,819
  28:   7c 60 49 e4     mtsrin  r3,r9
  2c:   4e 80 00 20     blr


I would expect GCC to realise that once unrolled, parameters to mtsr() are
constant, leading to something like the following:

mtsr 0, r3
addi r9,r3,273
mtsr 1, r9
addi r9,r3,546
mtsr 2, r9
addi r3,r3,819
mtsr 3, r3
blr

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

* [Bug c/100449] Unrolled loop ignores __building_constant_p
  2021-05-06 12:38 [Bug c/100449] New: Unrolled loop ignores __building_constant_p christophe.leroy at csgroup dot eu
@ 2021-05-07  7:02 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-07  7:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
__builtin_constant_p is resolved long before unrolling, your expectation off
here.

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

end of thread, other threads:[~2021-05-07  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 12:38 [Bug c/100449] New: Unrolled loop ignores __building_constant_p christophe.leroy at csgroup dot eu
2021-05-07  7:02 ` [Bug c/100449] " rguenth 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).