Open Quuxplusone opened 5 years ago
Attached badOptimize.7z
(967 bytes, application/x-7z-compressed): Archive containing the file necessary to reproduce this bug and the relevant generated assembly files
PPPS : Removing the while loop (leaving the code inside intact) makes it so that the optimizer converts the entire function to a jump to "fn"
Code from the file:
void f()
{
int d = 0, O = 0, g = fn();
while (d <= g)
{
++O;
for (int f = 0; f < O && d <= g; ++f)
++d;
for (int f = 0; f < O && d <= g; ++f)
++d;
}
}
C/C++'s semantics allow the compiler to assume that a loop without side-effects
will terminate. But this has not been defined for LLVM-IR. That is, the
LoopDeletion pass currently requires the loop to terminate.
Relevant discussion: https://lists.llvm.org/pipermail/llvm-dev/2017-
September/117854.html
Yeah, I understand that (I was pretty sure it was related to this). However, the optimizer still misses possible optimizations, such as the rather stupid double identical compare (which was the original reason I'd wanted to file this bug, as I only removed side effects while trying to narrow down the cause of this bug).
Having look over the output of -mllvm -print-after-all, looks like the "d <= g" condition of the while and inner for-loops are moved next to each other by LoopRotate, but then never combined. Could be a job for JumpThreading. At the time JumpThreading runs, the value of 'd' look different though, due to I PHINode that is later removed by PHIElimination.
badOptimize.7z
(967 bytes, application/x-7z-compressed)