[llvm-bugs] [Bug 45160] New: [InstCombine] Missed @llvm.usub.sat opportunity
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Mar 9 16:23:34 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45160
Bug ID: 45160
Summary: [InstCombine] Missed @llvm.usub.sat opportunity
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: lebedev.ri at gmail.com
CC: llvm-bugs at lists.llvm.org
Given https://godbolt.org/z/gGcybp
using size_type = unsigned;
size_type t0(size_type pos, size_type size) {
size_type bytesRemaining = (pos < size) ? size - pos : 0;
return ((bytesRemaining > 4)
? (size - pos - 4)
: 0);
}
we currently produce
define dso_local i32 @_Z2t0jj(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = tail call i32 @llvm.usub.sat.i32(i32 %1, i32 %0)
%4 = icmp ugt i32 %3, 4
%5 = sub i32 -4, %0
%6 = add i32 %5, %1
%7 = select i1 %4, i32 %6, i32 0
ret i32 %7
}
declare i32 @llvm.usub.sat.i32(i32, i32) #1
but we should instead produce
define dso_local i32 @_Z6squarejj(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = tail call i32 @llvm.usub.sat.i32(i32 %1, i32 %0)
%4 = tail call i32 @llvm.usub.sat.i32(i32 %3, i32 4)
ret i32 %4
}
declare i32 @llvm.usub.sat.i32(i32, i32) #1
----------------------------------------
define i8 @_Z6squarejj(i8 %0, i8 %1) {
%2:
%3 = usub_sat i8 %1, %0
%4 = icmp ugt i8 %3, 4
%5 = sub i8 252, %0
%6 = add i8 %5, %1
%7 = select i1 %4, i8 %6, i8 0
ret i8 %7
}
=>
define i8 @_Z6squarejj(i8 %0, i8 %1) {
%2:
%3 = usub_sat i8 %1, %0
%4 = usub_sat i8 %3, 4
ret i8 %4
}
Transformation seems to be correct!
Summary:
1 correct transformations
0 incorrect transformations
0 Alive2 errors
--
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/20200309/c923d2a8/attachment.html>
More information about the llvm-bugs
mailing list