[llvm-bugs] [Bug 46234] New: [Middle-end] Moving truncate before right-shift

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jun 7 12:59:55 PDT 2020


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

            Bug ID: 46234
           Summary: [Middle-end] Moving truncate before right-shift
           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

int src(long int num) {
    num &= 0xFFFFFFF;
    return num >> 2;
}
int tgt(long int num) {
    return (((unsigned int)num) << 4) >> 6;
}

----------------------------------------
define i32 @src(i64 %0) {
%1:
  %2 = lshr i64 %0, 2
  %3 = trunc i64 %2 to i32
  %4 = and i32 %3, 67108863
  ret i32 %4
}
=>
define i32 @tgt(i64 %0) {
%1:
  %2 = trunc i64 %0 to i32
  %3 = lshr i32 %2, 2
  %4 = and i32 %3, 67108863
  ret i32 %4
}
Transformation seems to be correct!

https://godbolt.org/z/V7xRAy
^ we do that in backend, but not middle-end.

-- 
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/20200607/3c7f6a38/attachment.html>


More information about the llvm-bugs mailing list