It does produce different code. This is for the Pi4 in 64-bit mode with GCC 11.1.
As you can see there is quite a lot more code without the option. This is very interesting, its years since I last looked at it.
In the "without option" code it refers to isinf() (which has been elided from the finite only code for obvious reasons), but where is it?
Edit: it loaded the infinity value from static memory and just did a simple compare on line 41.
With -ffinite-math-only
Code: Select all
1 .arch armv8-a+crc
2 .file "try.c"
3 // GNU C11 (GCC) version 11.1.0 (aarch64-unknown-linux-gnu)
4 // compiled by GNU C version 11.1.0, GMP version 6.1.0, MPFR version 3.
5
6 // GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=13107
7 // options passed: -march=armv8-a+crc -mcpu=cortex-a72 -mtune=cortex-a72 -ma
8 .text
9 .section .rodata.str1.1,"aMS",@progbits,1
10 .LC0:
11 0000 25660A00 .string "%f\n"
12 .section .text.startup,"ax",@progbits
13 .align 2
14 .global main
15 .hidden main
16 .type main, %function
17 main:
18 0000 F37BBEA9 stp x19, x30, [sp, -32]! //,,,
19 // try.c:6: int n = 1;
20 0004 33008052 mov w19, 1 // n,
21 // try.c:4: int main () {
22 0008 E80B00FD str d8, [sp, 16] //,
23 // try.c:5: double d = 1.0;
24 000c 08106E1E fmov d8, 1.0e+0 // d,
25 .L2:
26 // try.c:9: d = d * (d + n);
27 0010 6002621E scvtf d0, w19 // tmp97, n
28 // try.c:15: printf("%f\n", d);
29 0014 00000010 adr x0, .LC0 //,
30 // try.c:10: n = n + 1;
31 0018 73060011 add w19, w19, 1 // n, n,
32 // try.c:9: d = d * (d + n);
33 001c 0028681E fadd d0, d0, d8 // _2, tmp97, d
34 // try.c:9: d = d * (d + n);
35 0020 0809601E fmul d8, d8, d0 // d, d, _2
36 // try.c:15: printf("%f\n", d);
37 0024 0041601E fmov d0, d8 //, d
38 0028 00000094 bl printf //
39 002c F9FFFF17 b .L2 //
40 .size main, .-main
41 .ident "GCC: (GNU) 11.1.0"
and without:
Code: Select all
1 .arch armv8-a+crc
2 .file "try.c"
3 // GNU C11 (GCC) version 11.1.0 (aarch64-unknown-linux-gnu)
4 // compiled by GNU C version 11.1.0, GMP version 6.1.0, MPFR version 3.
5
6 // GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=13107
7 // options passed: -march=armv8-a+crc -mcpu=cortex-a72 -mtune=cortex-a72 -ma
8 .text
9 .section .rodata.str1.1,"aMS",@progbits,1
10 .LC0:
11 0000 52656163 .string "Reached infinity!"
11 68656420
11 696E6669
11 6E697479
11 2100
12 .LC1:
13 0012 25660A00 .string "%f\n"
14 .section .text.startup,"ax",@progbits
15 .align 2
16 .global main
17 .hidden main
18 .type main, %function
19 main:
20 0000 F37BBEA9 stp x19, x30, [sp, -32]! //,,,
21 // try.c:6: int n = 1;
22 0004 33008052 mov w19, 1 // n,
23 // try.c:4: int main () {
24 0008 E827016D stp d8, d9, [sp, 16] //,,
25 // try.c:5: double d = 1.0;
26 000c 08106E1E fmov d8, 1.0e+0 // d,
27 // try.c:11: if (isinf(d)) {
28 0010 4902005C ldr d9, .LC2 // tmp100,
29 .L3:
30 // try.c:9: d = d * (d + n);
31 0014 6002621E scvtf d0, w19 // tmp98, n
32 // try.c:10: n = n + 1;
33 0018 73060011 add w19, w19, 1 // n, n,
34 // try.c:9: d = d * (d + n);
35 001c 0028681E fadd d0, d0, d8 // _2, tmp98, d
36 // try.c:9: d = d * (d + n);
37 0020 0809601E fmul d8, d8, d0 // d, d, _2
38 // try.c:11: if (isinf(d)) {
39 0024 00C1601E fabs d0, d8 // tmp99, d
40 // try.c:11: if (isinf(d)) {
41 0028 0020691E fcmp d0, d9 // tmp99, tmp100
42 002c ED000054 ble .L2 //,
43 // try.c:12: printf("Reached infinity!\n");
44 0030 00000010 adr x0, .LC0 //,
45 0034 00000094 bl puts //
46 // try.c:18: }
47 0038 00008052 mov w0, 0 //,
48 003c E827416D ldp d8, d9, [sp, 16] //,,
49 0040 F37BC2A8 ldp x19, x30, [sp], 32 //,,,
50 0044 C0035FD6 ret
51 .L2:
52 // try.c:15: printf("%f\n", d);
53 0048 0041601E fmov d0, d8 //, d
54 004c 00000010 adr x0, .LC1 //,
55 0050 00000094 bl printf //
56 // try.c:9: d = d * (d + n);
57 0054 F0FFFF17 b .L3 //
58 .size main, .-main
59 .align 3
60 .LC2:
61 0058 FFFFFFFF .word -1
62 005c FFFFEF7F .word 2146435071
63 .ident "GCC: (GNU) 11.1.0"