-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[InstCombine] Miscompilation caused by incorrect ICMP predicate #123151
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
Comments
@llvm/issue-subscribers-bug Author: Min-Yih Hsu (mshockwave)
This is discovered from 445.gobmk when compiling it with RISC-V LLVM:
```
clang --target riscv64-linux-gnu -mcpu=sifive-p670 -O1 -mno-implicit-float ...
```
This is the reproducer snippet:
```llvm
define dso_local i1 @gg_sort.do.body.split(i32 %gap.0, i64 %width, ptr %base, ptr %div.out, ptr %add.ptr4.out, i64 noundef %nel) {
newFuncRoot:
%sub = add i64 %nel, -1
%mul = mul i64 %width, %sub
%add.ptr = getelementptr inbounds nuw i8, ptr %base, i64 %mul
br label %do.body.split
do.body.split: ; preds = %newFuncRoot for.end.exitStub: ; preds = %do.body.split for.body.exitStub: ; preds = %do.body.split
opt -p instcombine input.ll ...
InstCombine reduces ICMP on pointers (i.e. Changing ICMP into sign comparison solves this issue: |
Based on the nuw flags on the GEPs, I think InstCombine is correct. Is it possible |
InstCombine is correct: https://alive2.llvm.org/ce/z/SyRCQL
It is impossible. |
Can you rebuild |
Yes the sanitizer did point out there is a pointer overflow. I confirmed that
From the addresses reported by the sanitizer, it is likely that |
This is discovered from 445.gobmk when compiling it with RISC-V LLVM:
This is the reproducer snippet:
With this command:
The following code is generated:
InstCombine reduces ICMP on pointers (i.e.
%add.ptr
and%add.ptr4
) into ICMP of their offsets (i.e.%mul3
and%mul
). I think the problem here is%mul3
and%mul
might have different signs.Changing ICMP into sign comparison solves this issue:
%cmp5.not21 = icmp sgt i64 %mul3, %mul
The text was updated successfully, but these errors were encountered: