llvm / llvm/llvm-project

[IndVar] Miscompile due to removal of an infinite loop

Open
#183,906 6 comments 0 reactions 0 assignees View on GitHub
loopoptim miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This program is misoptimized by `IndVarSimplifyPass`:
```llvm
define void @func() unnamed_addr {
br label %1

1:
%2 = phi i8 [ 0, %0 ], [ %7, %6 ]
br label %4

3:
ret void

4:
%5 = icmp eq i8 %2, 1
br i1 %5, label %4, label %6

6:
%7 = add nuw i8 %2, 1
%8 = icmp eq i8 %7, -1
br i1 %8, label %3, label %1
}
```

which determines that `%8` is always true and so the branch which breaks out of the loop is always taken.

Compiler explorer: https://godbolt.org/z/EPsrzTz5W

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.