Open
Description
Bugzilla Link | 45152 |
Version | trunk |
OS | All |
CC | @DMG862,@efriedma-quic,@ecnelises,@aqjune,@LebedevRI,@jfbastien,@RKSimon,@nikic,@RalfJung,@programmerjake,@regehr,@rotateright,@yuanfang-chen |
Extended Description
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