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

wrong code at -O1, -Os and -O2 (but not -O3) on x86_64-linux-gnu (generated code hangs) #51618

Closed
zhendongsu opened this issue Oct 23, 2021 · 3 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@zhendongsu
Copy link

Bugzilla Link 52276
Resolution FIXED
Resolved on Oct 25, 2021 09:28
Version unspecified
OS All
CC @preames,@RKSimon,@rotateright

Extended Description

This appears to be a recent regression.

[679] % clangtk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2410fb4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
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/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
[680] %
[680] % clangtk -O0 small.c; ./a.out
[681] %
[681] % clangtk -O1 small.c
[682] % timeout -s 9 10 ./a.out
Killed
[683] %
[683] % cat small.c
int a, b;
int main() {
while ((a > 0) < ~a)
b++;
return 0;
}

@rotateright
Copy link
Contributor

cc'ing @​reames

This was caused/exposed by:
https://reviews.llvm.org/rG412eb07edd4e83afeb1e727e91213e2cbd771f29
https://reviews.llvm.org/D111836

define i32 @​#52276 (i32 %a, i32* %p) {
entry:
%cmp = icmp sgt i32 %a, 0
%conv = zext i1 %cmp to i32
%neg = xor i32 %a, -1
%cmp1 = icmp slt i32 %conv, %neg
br i1 %cmp1, label %ph, label %exit

ph:
%b = load i32, i32* %p, align 4
br label %loop

loop:
%inc1 = phi i32 [ %b, %ph ], [ %inc, %loop ]
%inc = add nsw i32 %inc1, 1
br i1 %cmp1, label %loop, label %crit_edge, !llvm.loop !​0

crit_edge:
%inc2 = phi i32 [ %inc, %loop ]
store i32 %inc2, i32* %p, align 4
br label %exit

exit:
ret i32 0
}

!​0 = distinct !{#0, !​1}
!​1 = !{!"llvm.loop.mustprogress"}

@preames
Copy link
Collaborator

preames commented Oct 25, 2021

Agreed, definitely a regression from my patch. I'd missed a hasOneUse check somewhere in the process of splitting and rebasing this. Will have a fix landed shortly, sorry for the breakage.

p.s. The bug is actually introduced before the patch fingered. That's simply the first one which exposes this particular use case.

@preames
Copy link
Collaborator

preames commented Oct 25, 2021

Should be fixed by:

commit f82cf61 (HEAD -> main, origin/main)
Author: Philip Reames listmail@philipreames.com
Date: Mon Oct 25 09:25:00 2021 -0700

[indvars] Fix pr52276 (missing one use check)

The recently added logic to canonicalize exit conditions to unsigned relies on facts which hold about the use (i.e. exit test).  Applying this blindly to the icmp is not legal, as there may be another use which never reaches the exit.  Restrict ourselves to case where we have a single use.

Please reopen if needed. I confirmed the reduced test case was fixed, but not the original C example.

@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
Projects
None yet
Development

No branches or pull requests

3 participants