Created attachment 8477
bug.ll
Compiling the following at -O1 or above in clang results in the division (a /
b) being hoisted outside the loop and a floating point exception.
#include <stdio.h>
__attribute__((noinline)) int f(int a, int b)
{
while (1) {
if (b) {
printf("%d\n", (a / b));
}
}
}
int main()
{
f(1, 0);
return 0;
}
I've attached the .ll file just before licm pass is run. The issue can be
recreated using opt -licm bug.ll -S and noticing that the sdiv instruction has
been hoisted before the loop.
bug.ll
(988 bytes, application/octet-stream)