[llvm-bugs] [Bug 48390] New: [InstCombine] Miscompile, improper substitution of uadd.sat

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 4 10:37:39 PST 2020


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

            Bug ID: 48390
           Summary: [InstCombine] Miscompile, improper substitution of
                    uadd.sat
           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

$ cat >bad.ll <<EOL
define i32 @src(i32 %x1, i32 %x2) {
  %x14 = add i32 %x1, %x2
  %x6 = icmp ugt i32 %x14, %x2
  %x9 = select i1 %x6, i32 %x14, i32 -1
  ret i32 %x9
}
EOL

$ opt bad.ll --instcombine -S
; ModuleID = 'bad.ll'
source_filename = "bad.ll"

define i32 @src(i32 %x1, i32 %x2) {
  %1 = call i32 @llvm.uadd.sat.i32(i32 %x2, i32 %x1)
  ret i32 %1
}

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare i32 @llvm.uadd.sat.i32(i32, i32) #0

attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }


Alive output:

----------------------------------------
define i32 @src(i32 %x1, i32 %x2) {
%0:
  %x14 = add i32 %x1, %x2
  %x6 = icmp ugt i32 %x14, %x2
  %x9 = select i1 %x6, i32 %x14, i32 4294967295
  ret i32 %x9
}
=>
define i32 @tgt(i32 %x1, i32 %x2) {
%0:
  %1 = uadd_sat i32 %x2, %x1
  ret i32 %1
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
i32 %x1 = #x00000000 (0)
i32 %x2 = #x04000000 (67108864)

Source:
i32 %x14 = #x04000000 (67108864)
i1 %x6 = #x0 (0)
i32 %x9 = #xffffffff (4294967295, -1)

Target:
i32 %1 = #x04000000 (67108864)
Source value: #xffffffff (4294967295, -1)
Target value: #x04000000 (67108864)

-- 
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/20201204/9394ab36/attachment.html>


More information about the llvm-bugs mailing list