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: unassignedb...@nondot.org
Reporter: lebedev...@gmail.com
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs