[llvm-dev] Aggressive optimization opportunity (original) (raw)
Roman Lebedev via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 15 04:42:26 PST 2019
- Previous message: [llvm-dev] Aggressive optimization opportunity
- Next message: [llvm-dev] Aggressive optimization opportunity
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 15, 2019 at 3:08 PM Zheng CZ Chen via llvm-dev <llvm-dev at lists.llvm.org> wrote:
Hi, There are some compilers with a aggressive optimization which restricts function pointer parameters. Let's say opt restrictargs. When restrictargs is turned on, compiler will treat all function pointer parameters as restrict one. int foo(int * a) + restrictargs 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 : 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? E.g. https://godbolt.org/z/gB98K0
Thanks.
BRS// Chen Zheng Power Compiler Backend Developer Roman.
LLVM Developers mailing list llvm-dev at lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
- Previous message: [llvm-dev] Aggressive optimization opportunity
- Next message: [llvm-dev] Aggressive optimization opportunity
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]