<html><body><p><font size="2">Hi,</font><br><br><font size="2">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.</font><br><br><i><font size="2">int foo(int * a) </font></i><font size="2">+ restrict_args opt </font><br><br><font size="2">equals to:</font><br><br><i><font size="2">int foo(int * restrict a)</font></i><br><br><br><font size="2">Here is a complete example:</font><br><font size="2">source code:</font><br><font size="2">extern int num;</font><br><i><font size="2">int foo(int * a)</font></i><br><i><font size="2">{</font></i><br><i><font size="2"> (*a) = 10;</font></i><br><i><font size="2"> num++;</font></i><br><i><font size="2"> (*a)++;</font></i><br><i><font size="2"> </font></i><br><i><font size="2"> return *a; </font></i><br><i><font size="2">}</font></i><br><br><font size="2">Using IBM xlc compiler with option -qrestrict at -O2, we get result:</font><br><br><font size="2">0000000000000000 <foo>:</font><br><font size="2"> 0: 00 00 4c 3c addis r2,r12,0</font><br><font size="2"> 4: 00 00 42 38 addi r2,r2,0</font><br><font size="2"> 8: 00 00 a2 3c addis r5,r2,0</font><br><font size="2"> c: 00 00 a5 e8 ld r5,0(r5)</font><br><font size="2"> 10: 0b 00 00 38 li r0,11</font><br><font size="2"> 14: 00 00 03 90 stw r0,0(r3)</font><br><font size="2"> 18: 00 00 85 80 lwz r4,0(r5)</font><br><font size="2"> </font><b><font size="2"> 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.</font></b><br><font size="2"> 20: 01 00 04 38 addi r0,r4,1</font><br><font size="2"> 24: 00 00 05 90 stw r0,0(r5)</font><br><font size="2"> 28: 20 00 80 4e blr</font><br><br><font size="2">Seems clang does not have such optimization. And I don't find similar option in gcc either.</font><br><br><font size="2">Is it possible to add this optimization into clang?</font><br><br><font size="2">Thanks.</font><br><br><font size="2">BRS//</font><br><font size="2">Chen Zheng</font><br><font size="2">Power Compiler Backend Developer</font><br><BR>
</body></html>