Hi,

I observed that in some ELF files there is code present which is not used.
It originates from integer arithmetics.
The following snipped should help to demonstrate the problem.

I have the function in the file foo.c:

```
unsigned long long foo(unsigned long a, unsigned long b)
{
        return ((unsigned long long) a + 0) / b;
}
```

Compiling it with `gcc -m32 -O2 -S foo.c` will give an assembler with
references to the symbols `__udivdi3` and `__divdi3`. But only a call to
`__udivdi3` is present.  Compiling with `-O1` instead of `-O2` will not
reference the symbol `__divdi3`.  The symbol is also not inserted if I use all
the activated optimizations reported be `-fverbose-asm` manually without `-O2`.
And if `-fno-tree-dominator-opts` and `-fno-tree-vrp` are used with `-O2`
`__divdi3` is also not present.

I am not sure how and why this is happening with `-O2` (and `-O3`, `-Os`),
but I suspect it should not be the case.

I tested this with gcc 10.1.0 and the current git (2e47c8c6eac).

Any thoughts?

Thanks,
Tobias

Reply via email to