LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 49541 - Infinite loop at -O2 and -Os
Summary: Infinite loop at -O2 and -Os
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: regression
: 49206 49556 (view as bug list)
Depends on:
Blocks: release-12.0.0
  Show dependency tree
 
Reported: 2021-03-11 08:33 PST by Haoxin Tu
Modified: 2021-03-31 04:41 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s): bd197ed0a57a e94372d1b395


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Haoxin Tu 2021-03-11 08:33:12 PST
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
Comment 1 Sanjay Patel 2021-03-11 12:06:12 PST
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?
Comment 2 Sanjay Patel 2021-03-11 13:48:55 PST
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
Comment 3 Haoxin Tu 2021-03-11 17:40:52 PST
(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
Comment 4 Sanjay Patel 2021-03-12 05:25:52 PST
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.
Comment 5 Sanjay Patel 2021-03-14 14:32:25 PDT
*** Bug 49556 has been marked as a duplicate of this bug. ***
Comment 6 Luke 2021-03-21 07:26:17 PDT
This is a regression that occurred between clang 6.0.0 and clang 7.0.0. Would a bisect help?
Comment 7 Sanjay Patel 2021-03-21 07:52:24 PDT
(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. :)
Comment 8 Luke 2021-03-26 13:11:32 PDT
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.
Comment 9 Tom Stellard 2021-03-29 16:44:10 PDT
Merged: e94372d1b395
Comment 10 Luke 2021-03-29 20:48:42 PDT
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.
Comment 11 Simon Pilgrim 2021-03-31 04:41:52 PDT
*** Bug 49206 has been marked as a duplicate of this bug. ***