[llvm] [TypePromotion] Support trunc-to-i1 conditions (PR #216311)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 14:25:56 PDT 2026
nikic wrote:
AI flagged a miscompile introduced by this change:
```llvm
; RUN: opt -passes=typepromotion -S < %s
target triple = "aarch64"
define i1 @f(i8 zeroext %x, i8 zeroext %y) {
%a = or i8 %x, %y
%t = trunc nsw i8 %a to i1
ret i1 %t
}
```
Results in:
```llvm
define i1 @f(i8 zeroext %x, i8 zeroext %y) {
%1 = zext i8 %x to i32
%2 = zext i8 %y to i32
%a = or i32 %1, %2
%t = trunc nsw i32 %a to i1
ret i1 %t
}
```
The issue here is that the `nsw` flag on the trunc is preserved. The original trunc may be nsw, while the widened one is not (e.g. for `%a == -1`).
https://github.com/llvm/llvm-project/pull/216311
More information about the llvm-commits
mailing list