Hi, all. This code, small.c, is a valid program but makes Clang trunk hung on at compile time at -O2 and -Os. Note that this issue also occurs in recently released versions of clang, e.g., clang-10, clang-11. $cat small.c #include <stdint.h> int a; void b(int c) { int32_t *d = a; uint64_t e; int8_t f = 4; uint16_t g; if (0) j: if (e <= (*d *= a)) goto j; i: if (c ? g %= f : *d) goto i; goto j; } $clang -O2 -w small.c (or -Os) //endless compiling $clang -v clang version 13.0.0 (https://github.com/llvm/llvm-project 590ac0a26af4c9f63d5564be8c13b12d409a7fd9) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/haoxin/haoxin-data/dut-research/compilers/llvm-project/build-20210310/bin Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Candidate multilib: .;@m64 Selected multilib: .;@m64 Thanks, Haoxin
Double-check my understanding: I used "opt -print-before-all", and I don't see any assume instructions in the function. The title of this bug report suggests that assumes are causing the inf-loop / explosion. Did I miss something?
I'm pretty sure that this is an actual infinite loop in -simplifycfg, but let me know if I'm not seeing this correctly. define void @PR49541(i32* %t1, i32 %a, i1 %bool) { entry: br label %i j: %t3 = phi i32 [ %b, %j ], [ %a, %cond.true ], [ %a, %cond.false ] %t2 = phi i32 [ %t2, %j ], [ %pre2, %cond.true ], [ 0, %cond.false ] %b = load i32, i32* %t1, align 4 br label %j i: %g.1 = phi i16 [ undef, %entry ], [ %g.1, %cond.false ] br i1 %bool, label %cond.false, label %cond.true cond.true: %tobool9.not = icmp eq i16 %g.1, 0 %pre2 = load i32, i32* %t1, align 4 br label %j cond.false: %t5 = load i32, i32* %t1, align 4 %b2 = icmp eq i32 %t5, 0 br i1 %b2, label %j, label %i } ------------------------------------------------------------------------ This will inf-loop with: $ opt -simplifycfg 49541.ll -S -keep-loops=false -sink-common-insts=true
(In reply to Sanjay Patel from comment #1) > Double-check my understanding: > I used "opt -print-before-all", and I don't see any assume instructions in > the function. The title of this bug report suggests that assumes are causing > the inf-loop / explosion. Did I miss something? Hi Sanjay! Thanks for your checking! I think it's my fault that I have misunderstood something here. So I changed the title to "Infinite loop at -O2 and -Os". By the way, can you also help check bug 49206? I think it's an infinite loop issue as well and still exists in the current trunk and last released versions. Thanks again for your quick and nice checking! Cheers, Haoxin
Here's a minimal fix for trunk: https://reviews.llvm.org/rGbd197ed0a57a I'm going to mark this as blocking the 12.0 release, but it might be too late to get included.
*** Bug 49556 has been marked as a duplicate of this bug. ***
This is a regression that occurred between clang 6.0.0 and clang 7.0.0. Would a bisect help?
(In reply to Luke from comment #6) > This is a regression that occurred between clang 6.0.0 and clang 7.0.0. > Would a bisect help? AFAIK, the bug is fixed in trunk, and it's still potentially going to make the 12.0 release. But I doubt anyone is going to patch anything older than that? Not sure if that was the question though. :)
No, I was saying that this code worked in clang 6 and below. I was asking if a bisect for the cause of the regression would help with the fix.
Merged: e94372d1b395
I did get around to bisecting this regression. It was caused by https://github.com/llvm/llvm-project/commit/66182d6c3805d167 Thanks for fixing it Sanjay.
*** Bug 49206 has been marked as a duplicate of this bug. ***