[llvm-bugs] [Bug 44102] New: Missed canonicalizations for losslessness checks of signed integer demotions

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 21 05:50:48 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44102

            Bug ID: 44102
           Summary: Missed canonicalizations for losslessness checks of
                    signed 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

Much like https://bugs.llvm.org/show_bug.cgi?id=44100
we have a missed canonicalization for signed pattern:

Given 

signed short t4(signed short x) {
  x+=1;
  return x;
}
signed short t5(signed short x) {
  x-=1;
  return x;
}

With -fsanitize=implicit-conversion we produce:

  %2 = sext i16 %0 to i32, !dbg !15
  %5 = add nsw i32 %2, 32769, !dbg !15
  %6 = icmp ult i32 %5, 65536, !dbg !15

and 

  %2 = sext i16 %0 to i32, !dbg !22
  %5 = add nsw i32 %2, 32767, !dbg !22
  %6 = icmp ult i32 %5, 65536, !dbg !22

https://godbolt.org/z/eyc6qN

But in these cases we can simply check the original %0:

Name: sext-signed-trunc-check - increment
Pre: C2 == 65536 && C1 == (C2/2)+C3 && C3 > 0 && C3 u<= C2
  %ZZ_IGNOREME = C3
  %conv = sext i16 %x to i32
  %zz = add i32 %conv, C1
  %cmp = icmp ult i32 %zz, C2
=>
  %ZZ_IGNOREME = C3
  %cmp = icmp slt i16 %x, (trunc (C2/2) - trunc (C3))

Name: sext-signed-trunc-check - decrement
Pre: C2 == 65536 && C1 == (C2/2)+C3 && C3 < 0 && C3 > -C2
  %ZZ_IGNOREME = C3
  %conv = sext i16 %x to i32
  %zz = add i32 %conv, C1
  %cmp = icmp ult i32 %zz, C2
=>
  %ZZ_IGNOREME = C3
  %cmp = icmp sge i16 %x, (-(trunc (C2/2)) - (trunc (C3)))


https://rise4fun.com/Alive/GC57

-- 
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/361cb08f/attachment.html>


More information about the llvm-bugs mailing list