[llvm-dev] Aggressive optimization opportunity

Zheng CZ Chen via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 15 04:07:45 PST 2019



Hi,

There are some compilers with a aggressive optimization which restricts
function pointer parameters. Let's say opt restrict_args.  When
restrict_args is turned on, compiler will treat all function pointer
parameters as restrict one.

int foo(int * a) + restrict_args opt

equals to:

int foo(int * restrict a)


Here is a complete example:
source code:
extern int num;
int foo(int * a)
{
  (*a) = 10;
  num++;
  (*a)++;

  return *a;
}

Using IBM xlc compiler with option -qrestrict at -O2, we get result:

0000000000000000 <foo>:
   0:   00 00 4c 3c     addis   r2,r12,0
   4:   00 00 42 38     addi    r2,r2,0
   8:   00 00 a2 3c     addis   r5,r2,0
   c:   00 00 a5 e8     ld      r5,0(r5)
  10:   0b 00 00 38     li      r0,11
  14:   00 00 03 90     stw     r0,0(r3)
  18:   00 00 85 80     lwz     r4,0(r5)
  1c:   0b 00 60 38     li      r3,11      ------>since we confirm num will
not change the content where pointer to, compiler can directly return 11.
  20:   01 00 04 38     addi    r0,r4,1
  24:   00 00 05 90     stw     r0,0(r5)
  28:   20 00 80 4e     blr

Seems clang does not have such optimization. And I don't find similar
option in gcc either.

Is it possible to add this optimization into clang?

Thanks.

BRS//
Chen Zheng
Power Compiler Backend Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190115/3d99adf6/attachment.html>


More information about the llvm-dev mailing list