[llvm-bugs] [Bug 48343] New: [InstCombine] Miscompile of sext(ashr(shl(trunc())))

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 30 16:13:49 PST 2020


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

            Bug ID: 48343
           Summary: [InstCombine] Miscompile of sext(ashr(shl(trunc())))
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: meheff at google.com
                CC: llvm-bugs at lists.llvm.org

Example failing input:

define i10 @test(i10 %i) {
  %a = trunc i10 %i to i3
  %b = shl i3 %a, 2
  %c = ashr i3 %b, 2
  %d = sext i3 %c to i10
  ret i10 %d
}

Bad code after optimizations:

$ opt -S --instcombine /tmp/fail.ll
; ModuleID = '/tmp/fail.ll'
source_filename = "/tmp/fail.ll"

define i10 @test(i10 %i) {
  %d1 = shl i10 %i, 1
  %d = ashr exact i10 %d1, 1
  ret i10 %d
}


This should be shifting left by 9 then shifting right by 9, but (I think) the
optimization tries to create a 9 of type i3 which is the source of the bug:

https://github.com/llvm/llvm-project/blob/8cdf4920c47ddd3d60bdc3298f525512d483ce65/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp#L1526

-- 
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/20201201/ee804368/attachment.html>


More information about the llvm-bugs mailing list