1 ; RUN: llc < %s | FileCheck %s
5 ; extern "C" int array[4];
6 ; extern "C" void global_array(int idx1, int idx2, int idx3) {
15 ; extern "C" __declspec(dllimport) int imported;
16 ; extern "C" void access_imported() {
26 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
27 target triple = "x86_64-pc-windows-msvc18.0.0"
29 %eh.ThrowInfo = type { i32, i32, i32, i32 }
31 @array = external global [4 x i32], align 16
32 @imported = external dllimport global i32, align 4
34 ; Function Attrs: uwtable
35 define void @global_array(i32 %idx1, i32 %idx2, i32 %idx3) #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
37 %idxprom = sext i32 %idx1 to i64
38 %arrayidx = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom
39 store i32 111, i32* %arrayidx, align 4, !tbaa !2
40 invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
41 to label %unreachable unwind label %catch.dispatch
43 catch.dispatch: ; preds = %entry
44 %cs1 = catchswitch within none [label %catch] unwind to caller
46 catch: ; preds = %catch.dispatch
47 %0 = catchpad within %cs1 [i8* null, i32 64, i8* null]
48 %idxprom1 = sext i32 %idx2 to i64
49 %arrayidx2 = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom1
50 store i32 222, i32* %arrayidx2, align 4, !tbaa !2
51 catchret from %0 to label %try.cont
53 try.cont: ; preds = %catch
54 %idxprom3 = sext i32 %idx3 to i64
55 %arrayidx4 = getelementptr inbounds [4 x i32], [4 x i32]* @array, i64 0, i64 %idxprom3
56 store i32 333, i32* %arrayidx4, align 4, !tbaa !2
59 unreachable: ; preds = %entry
63 ; CHECK-LABEL: global_array: # @global_array
66 ; CHECK: movslq %ecx, %[[idx:[^ ]*]]
67 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
68 ; CHECK: movl $111, (%[[base]],%[[idx]],4)
69 ; Might throw an exception and return to below...
70 ; CHECK: callq _CxxThrowException
71 ; Third array access must remat the address of array
72 ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]]
73 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
74 ; CHECK: movl $333, (%[[base]],%[[idx]],4)
78 ; CHECK: "?catch$2@?0?global_array@4HA":
80 ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]]
81 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
82 ; CHECK: movl $222, (%[[base]],%[[idx]],4)
84 ; CHECK: retq # CATCHRET
86 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
88 declare i32 @__CxxFrameHandler3(...)
90 ; Function Attrs: uwtable
91 define void @access_imported() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
93 store i32 111, i32* @imported, align 4, !tbaa !2
94 invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
95 to label %unreachable unwind label %catch.dispatch
97 catch.dispatch: ; preds = %entry
98 %cs1 = catchswitch within none [label %catch] unwind to caller
100 catch: ; preds = %catch.dispatch
101 %0 = catchpad within %cs1 [i8* null, i32 64, i8* null]
102 store i32 222, i32* @imported, align 4, !tbaa !2
103 catchret from %0 to label %try.cont
105 try.cont: ; preds = %catch
106 store i32 333, i32* @imported, align 4, !tbaa !2
109 unreachable: ; preds = %entry
113 ; CHECK-LABEL: access_imported: # @access_imported
115 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
116 ; CHECK: movl $111, (%[[base]])
117 ; Might throw an exception and return to below...
118 ; CHECK: callq _CxxThrowException
119 ; Third access must reload the address of imported
120 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
121 ; CHECK: movl $333, (%[[base]])
125 ; CHECK: "?catch$2@?0?access_imported@4HA":
127 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
128 ; CHECK: movl $222, (%[[base]])
130 ; CHECK: retq # CATCHRET
133 attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
134 attributes #1 = { noreturn }
136 !llvm.module.flags = !{!0}
139 !0 = !{i32 1, !"PIC Level", i32 2}
140 !1 = !{!"clang version 3.8.0 "}
141 !2 = !{!3, !3, i64 0}
142 !3 = !{!"int", !4, i64 0}
143 !4 = !{!"omnipotent char", !5, i64 0}
144 !5 = !{!"Simple C/C++ TBAA"}