[llvm-bugs] [Bug 45152] New: Instcombine incorrectly transforms store i64 -> store double

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 9 08:33:20 PDT 2020


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

            Bug ID: 45152
           Summary: Instcombine incorrectly transforms store i64 -> store
                    double
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: juneyoung.lee at sf.snu.ac.kr, llvm-bugs at lists.llvm.org,
                    nikita.ppv at gmail.com, regehr at cs.utah.edu,
                    spatel+llvm at rotateright.com

The unit test "test/Transforms/InstCombine/bitcast-phi-uselistorder.ll" shows
an incorrect transformation from load+store i64 into load/store double. These
are not equivalent because NaN values can be canonicalized by the CPU so the
store double can write a different bit-pattern than store i64.

Alive2's counterexample:
@Q = global 8 bytes, align 8

define double @test(i1 %c, * %p) {
%entry:
  br i1 %c, label %if, label %end

%if:
  %__constexpr_0 = bitcast * @Q to *
  %load = load i64, * %__constexpr_0, align 8
  br label %end

%end:
  %phi = phi i64 [ 0, %entry ], [ %load, %if ]
  store i64 %phi, * %p, align 8
  %cast = bitcast i64 %phi to double
  ret double %cast
}
=>
@Q = global 8 bytes, align 8

define double @test(i1 %c, * %p) {
%entry:
  br i1 %c, label %if, label %end

%if:
  %load1 = load double, * @Q, align 8
  br label %end

%end:
  %0 = phi double [ 0.000000, %entry ], [ %load1, %if ]
  %1 = bitcast * %p to *
  store double %0, * %1, align 8
  ret double %0
}
Transformation doesn't verify!
ERROR: Mismatch in memory

Example:
i1 %c = #x1 (1)
* %p = pointer(non-local, block_id=2, offset=64)

Source:
* %__constexpr_0 = pointer(non-local, block_id=1, offset=0)
i64 %load = #x7ff0000001000000 (9218868437244182528)
i64 %phi = #x7ff0000001000000 (9218868437244182528)
double %cast = NaN

Target:
double %load1 = NaN
double %0 = NaN
* %1 = pointer(non-local, block_id=2, offset=64)

Mismatch in pointer(non-local, block_id=2, offset=64)
Source value: #x7ff0000001000000
Target value: #x7ff0000000020000

-- 
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/20200309/5d8029e5/attachment.html>


More information about the llvm-bugs mailing list