Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop at -O2 and -Os #48885

Closed
haoxintu opened this issue Mar 11, 2021 · 12 comments
Closed

Infinite loop at -O2 and -Os #48885

haoxintu opened this issue Mar 11, 2021 · 12 comments
Labels
bugzilla Issues migrated from bugzilla regression

Comments

@haoxintu
Copy link

Bugzilla Link 49541
Resolution FIXED
Resolved on Mar 31, 2021 04:41
Version trunk
OS All
Blocks #48246
CC @slacka,@rotateright,@sstefan1
Fixed by commit(s) bd197ed e94372d

Extended Description

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 590ac0a)
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

@rotateright
Copy link
Contributor

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?

@rotateright
Copy link
Contributor

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 @​#49541 (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

@haoxintu
Copy link
Author

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

@rotateright
Copy link
Contributor

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.

@rotateright
Copy link
Contributor

*** Bug llvm/llvm-bugzilla-archive#49556 has been marked as a duplicate of this bug. ***

@slacka
Copy link
Mannequin

slacka mannequin commented Mar 21, 2021

This is a regression that occurred between clang 6.0.0 and clang 7.0.0. Would a bisect help?

@rotateright
Copy link
Contributor

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. :)

@slacka
Copy link
Mannequin

slacka mannequin commented Mar 26, 2021

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.

@tstellar
Copy link
Collaborator

Merged: e94372d

@slacka
Copy link
Mannequin

slacka mannequin commented Mar 30, 2021

I did get around to bisecting this regression. It was caused by 66182d6c3805d167

Thanks for fixing it Sanjay.

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 31, 2021

*** Bug llvm/llvm-bugzilla-archive#49206 has been marked as a duplicate of this bug. ***

@rotateright
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#49556

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla regression
Projects
None yet
Development

No branches or pull requests

4 participants