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 %0 = catchpad [i8* null, i32 64, i8* null]
45 to label %catch unwind label %catchendblock
47 catch: ; preds = %catch.dispatch
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 %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 catchendblock: ; preds = %catch.dispatch
60 catchendpad unwind to caller
62 unreachable: ; preds = %entry
66 ; CHECK-LABEL: global_array: # @global_array
69 ; CHECK: movslq %ecx, %[[idx:[^ ]*]]
70 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
71 ; CHECK: movl $111, (%[[base]],%[[idx]],4)
72 ; Might throw an exception and return to below...
73 ; CHECK: callq _CxxThrowException
74 ; Third array access must remat the address of array
75 ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]]
76 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
77 ; CHECK: movl $333, (%[[base]],%[[idx]],4)
81 ; CHECK: "?catch$2@?0?global_array@4HA":
83 ; CHECK: movslq {{.*}}, %[[idx:[^ ]*]]
84 ; CHECK: leaq array(%rip), %[[base:[^ ]*]]
85 ; CHECK: movl $222, (%[[base]],%[[idx]],4)
87 ; CHECK: retq # CATCHRET
89 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
91 declare i32 @__CxxFrameHandler3(...)
93 ; Function Attrs: uwtable
94 define void @access_imported() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
96 store i32 111, i32* @imported, align 4, !tbaa !2
97 invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
98 to label %unreachable unwind label %catch.dispatch
100 catch.dispatch: ; preds = %entry
101 %0 = catchpad [i8* null, i32 64, i8* null]
102 to label %catch unwind label %catchendblock
104 catch: ; preds = %catch.dispatch
105 store i32 222, i32* @imported, align 4, !tbaa !2
106 catchret %0 to label %try.cont
108 try.cont: ; preds = %catch
109 store i32 333, i32* @imported, align 4, !tbaa !2
112 catchendblock: ; preds = %catch.dispatch
113 catchendpad unwind to caller
115 unreachable: ; preds = %entry
119 ; CHECK-LABEL: access_imported: # @access_imported
121 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
122 ; CHECK: movl $111, (%[[base]])
123 ; Might throw an exception and return to below...
124 ; CHECK: callq _CxxThrowException
125 ; Third access must reload the address of imported
126 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
127 ; CHECK: movl $333, (%[[base]])
131 ; CHECK: "?catch$2@?0?access_imported@4HA":
133 ; CHECK: movq __imp_imported(%rip), %[[base:[^ ]*]]
134 ; CHECK: movl $222, (%[[base]])
136 ; CHECK: retq # CATCHRET
139 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" }
140 attributes #1 = { noreturn }
142 !llvm.module.flags = !{!0}
145 !0 = !{i32 1, !"PIC Level", i32 2}
146 !1 = !{!"clang version 3.8.0 "}
147 !2 = !{!3, !3, i64 0}
148 !3 = !{!"int", !4, i64 0}
149 !4 = !{!"omnipotent char", !5, i64 0}
150 !5 = !{!"Simple C/C++ TBAA"}