[llvm-bugs] [Bug 44100] New: Missed canonicalizations for losslessness checks of unsigned integer demotions
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 21 03:42:54 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44100
Bug ID: 44100
Summary: Missed canonicalizations for losslessness checks of
unsigned integer demotions
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
unsigned short t0(unsigned short x) {
x+=1;
return x;
}
unsigned short t1(unsigned short x) {
x-=1;
return x;
}
With -fsanitize=implicit-conversion we produce:
%3 = add nuw nsw i32 %2, 1, !dbg !15
%4 = trunc i32 %3 to i16, !dbg !15
%5 = icmp ult i32 %3, 65536, !dbg !15
and
%2 = zext i16 %0 to i32, !dbg !22
%3 = add nsw i32 %2, -1, !dbg !22
%4 = trunc i32 %3 to i16, !dbg !22
%5 = icmp ult i32 %3, 65536, !dbg !22
https://godbolt.org/z/Us33sA
But in these cases we can simply check the original %2:
Name: unsigned truncation check - increment
Pre: C2 u>= C1
%add = add nuw i32 %conv, C1 ; has extra uses
%cmp = icmp ult i32 %add, C2 ; is truncation NUW?
=>
%cmp = icmp ult i32 %conv, (C2-C1)
Name: unsigned truncation check - decrement
Pre: C1 <= 0 ; C1 is non-positive
%conv = zext i16 %x to i32
%add = add i32 %conv, C1 ; has extra uses
%cmp = icmp ult i32 %add, 65536 ; is truncation NUW?
=>
%cmp = icmp uge i32 %conv, -C1
https://rise4fun.com/Alive/x35G
--
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/20191121/82d5a18a/attachment-0001.html>
More information about the llvm-bugs
mailing list