1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3; Ensure that volatile loads followed by a bitcast don't get transformed into a
4; volatile load of the bitcast-target type. This is unlikely to provide much in
5; terms of optimizations, and might break the programmer's expectation for code
6; generation, however brittle that expectation might be.
7;
8; See llvm.org/D75644 and llvm.org/D75505
9target datalayout = "e-p:64:64-i32:32:32-i64:64:64-f32:32:32-f64:64:64"
10
11define float @float_load(i32* %addr) {
12; CHECK-LABEL: @float_load(
13; CHECK:         %i32 = load volatile i32, i32* %addr, align 4
14; CHECK-NEXT:    %float = bitcast i32 %i32 to float
15; CHECK-NEXT:    ret float %float
16  %i32 = load volatile i32, i32* %addr, align 4
17  %float = bitcast i32 %i32 to float
18  ret float %float
19}
20
21define i32 @i32_load(float* %addr) {
22; CHECK-LABEL: @i32_load(
23; CHECK:         %float = load volatile float, float* %addr, align 4
24; CHECK-NEXT:    %i32 = bitcast float %float to i32
25; CHECK-NEXT:    ret i32 %i32
26  %float = load volatile float, float* %addr, align 4
27  %i32 = bitcast float %float to i32
28  ret i32 %i32
29}
30
31define double @double_load(i64* %addr) {
32; CHECK-LABEL: @double_load(
33; CHECK:         %i64 = load volatile i64, i64* %addr, align 8
34; CHECK-NEXT:    %double = bitcast i64 %i64 to double
35; CHECK-NEXT:    ret double %double
36  %i64 = load volatile i64, i64* %addr, align 8
37  %double = bitcast i64 %i64 to double
38  ret double %double
39}
40
41define i64 @i64_load(double* %addr) {
42; CHECK-LABEL: @i64_load(
43; CHECK:         %double = load volatile double, double* %addr, align 8
44; CHECK-NEXT:    %i64 = bitcast double %double to i64
45; CHECK-NEXT:    ret i64 %i64
46  %double = load volatile double, double* %addr, align 8
47  %i64 = bitcast double %double to i64
48  ret i64 %i64
49}
50
51define i8* @ptr_load(i64* %addr) {
52; CHECK-LABEL: @ptr_load(
53; CHECK:         %i64 = load volatile i64, i64* %addr, align 8
54; CHECK-NEXT:    %ptr = inttoptr i64 %i64 to i8*
55; CHECK-NEXT:    ret i8* %ptr
56  %i64 = load volatile i64, i64* %addr, align 8
57  %ptr = inttoptr i64 %i64 to i8*
58  ret i8* %ptr
59}
60