Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

licm incorrectly hoists divide out of infinite loop, resulting in floating point exception #12814

Closed Quuxplusone closed 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR12706
Status RESOLVED FIXED
Importance P normal
Reported by Richard Osborne (richard@xmos.com)
Reported on 2012-04-30 12:47:53 -0700
Last modified on 2012-04-30 23:03:12 -0700
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, nlewycky@google.com
Fixed by commit(s)
Attachments bug.ll (988 bytes, application/octet-stream)
Blocks
Blocked by
See also
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.
Quuxplusone commented 12 years ago

Attached bug.ll (988 bytes, application/octet-stream): bug.ll

Quuxplusone commented 12 years ago

Fixed in r155884. Thanks for the great testcase!