[llvm-bugs] [Bug 38146] New: `add nsw` + `sadd.with.overflow` with constants should fold
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jul 12 00:50:25 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38146
Bug ID: 38146
Summary: `add nsw` + `sadd.with.overflow` with constants should
fold
Product: new-bugs
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: me22.ca at gmail.com
CC: llvm-bugs at lists.llvm.org
```
%3 = add nsw i32 %1, 7
%4 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %3, i32 13)
```
should be folded to
```
%4 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %1, i32 20)
```
Repro in clang: https://godbolt.org/g/DM5Gq9
```
#include <optional>
std::optional<int> test_nsw_sadd_fold(int num) {
num += 7;
int r;
if (__builtin_sadd_overflow(num, 13, &r)) {
return {};
}
return r;
}
```
Cases for `.add_nsw(C1).sadd_overflow(C2)`:
- Same sign can be folded to a single overflow call
- Opposite signs with |C2|>|C1| can be folded to a single overflow call
- Opposite signs with |C2|<=|C1| can be folded to a single nsw call
(Similarly, just simpler, for `.add_nuw(C1).uadd_overflow(C2)`.)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180712/2883af62/attachment.html>
More information about the llvm-bugs
mailing list