-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[InstCombine] infinite loop in InstCombinerImpl::visitZExt() #51104
Comments
assigned to @rotateright |
This is an infinite loop from opposing transforms in InstCombine (updated bug title). I'm not sure exactly yet, but transformZExtICmp() does something unusual where it checks if it can eliminate instructions before creating new ones. If that doesn't work as expected, we could be creating extra instructions which some other transform then tries to reduce. |
transformZExtICmp() is called twice: first to determine if we have a suitable pattern to reduce and second to actually reduce that pattern. The problem is that transformZExtICmp() calls computeKnownBits (ValueTracking) with different parameters (context instruction) on the successive calls. On this example, that makes a difference on the bits that are reported as known. So we determine that a transform is possible, but then fail to adequately reduce the instructions, so it triggers some other transform to invert this sequence. |
I don't know exactly what is required to cause the loop, but it seems to take quite a bit to get computeKnownBits to behave differently. Here is my current IR reduction: declare void @llvm.assume(i1 noundef) #0 define i1 @#51762 (i32 %i, i32 %t0, i16 %t1, i64 %p, i32* %d, i32* %f) { for.cond: cond.true: for.end11: %lor.ext = zext i1 %spec.select57 to i32 |
Should be fixed after: |
Extended Description
Hi all.
The following valid program makes the trunk version of clang hang at -O1.
$cat small.c
#include <stdint.h>
int a, c, d, e, f;
int16_t b;
void g() {
uint64_t i;
uint64_t *r = &i;
int16_t j;
uint64_t *k;
uint64_t **l = &r;
for (; *k;) {
int32_t *m = d;
if (e ? **l = c : 0) {
int16_t n;
int32_t o = d;
if (a)
m = *l;
for (n = 4; n; *m = o)
;
int16_t *p = j;
q:
j = *p;
}
}
if (*r /= (b % *r || 0 == *r) % (f += d >= b))
goto q;
}
$clang -w -O1 small.c
//endless compiling
$clang -v
clang version 14.0.0 (https://github.com/llvm/llvm-project fa69ccd)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
Thanks,
Haoxin
The text was updated successfully, but these errors were encountered: