1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; Run with --no_x86_scrub_rip because we care a lot about how globals are 3; accessed in the code model. 4 5; RUN: llc < %s -relocation-model=static -code-model=small | FileCheck %s --check-prefix=CHECK --check-prefix=SMALL-STATIC 6; RUN: llc < %s -relocation-model=static -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-STATIC 7; RUN: llc < %s -relocation-model=static -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-STATIC 8; RUN: llc < %s -relocation-model=pic -code-model=small | FileCheck %s --check-prefix=CHECK --check-prefix=SMALL-PIC 9; RUN: llc < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC 10; RUN: llc < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC 11 12; Generated from this C source: 13; 14; static int static_data[10]; 15; int global_data[10] = {1, 2}; 16; extern int extern_data[10]; 17; 18; int *lea_static_data() { return &static_data[0]; } 19; int *lea_global_data() { return &global_data[0]; } 20; int *lea_extern_data() { return &extern_data[0]; } 21; 22; static void static_fn(void) {} 23; void global_fn(void) {} 24; void extern_fn(void); 25; 26; typedef void (*void_fn)(void); 27; void_fn lea_static_fn() { return &static_fn; } 28; void_fn lea_global_fn() { return &global_fn; } 29; void_fn lea_extern_fn() { return &extern_fn; } 30 31 32; ModuleID = 'model.c' 33source_filename = "model.c" 34target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 35target triple = "x86_64--linux" 36 37@global_data = dso_local global [10 x i32] [i32 1, i32 2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], align 16 38@static_data = internal global [10 x i32] zeroinitializer, align 16 39@extern_data = external global [10 x i32], align 16 40 41define dso_local i32* @lea_static_data() #0 { 42; SMALL-STATIC-LABEL: lea_static_data: 43; SMALL-STATIC: # %bb.0: 44; SMALL-STATIC-NEXT: movl $static_data, %eax 45; SMALL-STATIC-NEXT: retq 46; 47; MEDIUM-STATIC-LABEL: lea_static_data: 48; MEDIUM-STATIC: # %bb.0: 49; MEDIUM-STATIC-NEXT: movabsq $static_data, %rax 50; MEDIUM-STATIC-NEXT: retq 51; 52; LARGE-STATIC-LABEL: lea_static_data: 53; LARGE-STATIC: # %bb.0: 54; LARGE-STATIC-NEXT: movabsq $static_data, %rax 55; LARGE-STATIC-NEXT: retq 56; 57; SMALL-PIC-LABEL: lea_static_data: 58; SMALL-PIC: # %bb.0: 59; SMALL-PIC-NEXT: leaq static_data(%rip), %rax 60; SMALL-PIC-NEXT: retq 61; 62; MEDIUM-PIC-LABEL: lea_static_data: 63; MEDIUM-PIC: # %bb.0: 64; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx 65; MEDIUM-PIC-NEXT: movabsq $static_data@GOTOFF, %rax 66; MEDIUM-PIC-NEXT: addq %rcx, %rax 67; MEDIUM-PIC-NEXT: retq 68; 69; LARGE-PIC-LABEL: lea_static_data: 70; LARGE-PIC: # %bb.0: 71; LARGE-PIC-NEXT: .Ltmp0: 72; LARGE-PIC-NEXT: leaq .Ltmp0(%rip), %rcx 73; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp0, %rax 74; LARGE-PIC-NEXT: addq %rax, %rcx 75; LARGE-PIC-NEXT: movabsq $static_data@GOTOFF, %rax 76; LARGE-PIC-NEXT: addq %rcx, %rax 77; LARGE-PIC-NEXT: retq 78 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @static_data, i64 0, i64 0) 79} 80 81define dso_local i32* @lea_global_data() #0 { 82; SMALL-STATIC-LABEL: lea_global_data: 83; SMALL-STATIC: # %bb.0: 84; SMALL-STATIC-NEXT: movl $global_data, %eax 85; SMALL-STATIC-NEXT: retq 86; 87; MEDIUM-STATIC-LABEL: lea_global_data: 88; MEDIUM-STATIC: # %bb.0: 89; MEDIUM-STATIC-NEXT: movabsq $global_data, %rax 90; MEDIUM-STATIC-NEXT: retq 91; 92; LARGE-STATIC-LABEL: lea_global_data: 93; LARGE-STATIC: # %bb.0: 94; LARGE-STATIC-NEXT: movabsq $global_data, %rax 95; LARGE-STATIC-NEXT: retq 96; 97; SMALL-PIC-LABEL: lea_global_data: 98; SMALL-PIC: # %bb.0: 99; SMALL-PIC-NEXT: leaq global_data(%rip), %rax 100; SMALL-PIC-NEXT: retq 101; 102; MEDIUM-PIC-LABEL: lea_global_data: 103; MEDIUM-PIC: # %bb.0: 104; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx 105; MEDIUM-PIC-NEXT: movabsq $global_data@GOTOFF, %rax 106; MEDIUM-PIC-NEXT: addq %rcx, %rax 107; MEDIUM-PIC-NEXT: retq 108; 109; LARGE-PIC-LABEL: lea_global_data: 110; LARGE-PIC: # %bb.0: 111; LARGE-PIC-NEXT: .Ltmp1: 112; LARGE-PIC-NEXT: leaq .Ltmp1(%rip), %rcx 113; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp1, %rax 114; LARGE-PIC-NEXT: addq %rax, %rcx 115; LARGE-PIC-NEXT: movabsq $global_data@GOTOFF, %rax 116; LARGE-PIC-NEXT: addq %rcx, %rax 117; LARGE-PIC-NEXT: retq 118 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @global_data, i64 0, i64 0) 119} 120 121define dso_local i32* @lea_extern_data() #0 { 122; SMALL-STATIC-LABEL: lea_extern_data: 123; SMALL-STATIC: # %bb.0: 124; SMALL-STATIC-NEXT: movl $extern_data, %eax 125; SMALL-STATIC-NEXT: retq 126; 127; MEDIUM-STATIC-LABEL: lea_extern_data: 128; MEDIUM-STATIC: # %bb.0: 129; MEDIUM-STATIC-NEXT: movabsq $extern_data, %rax 130; MEDIUM-STATIC-NEXT: retq 131; 132; LARGE-STATIC-LABEL: lea_extern_data: 133; LARGE-STATIC: # %bb.0: 134; LARGE-STATIC-NEXT: movabsq $extern_data, %rax 135; LARGE-STATIC-NEXT: retq 136; 137; SMALL-PIC-LABEL: lea_extern_data: 138; SMALL-PIC: # %bb.0: 139; SMALL-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax 140; SMALL-PIC-NEXT: retq 141; 142; MEDIUM-PIC-LABEL: lea_extern_data: 143; MEDIUM-PIC: # %bb.0: 144; MEDIUM-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax 145; MEDIUM-PIC-NEXT: retq 146; 147; LARGE-PIC-LABEL: lea_extern_data: 148; LARGE-PIC: # %bb.0: 149; LARGE-PIC-NEXT: .Ltmp2: 150; LARGE-PIC-NEXT: leaq .Ltmp2(%rip), %rax 151; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp2, %rcx 152; LARGE-PIC-NEXT: addq %rcx, %rax 153; LARGE-PIC-NEXT: movabsq $extern_data@GOT, %rcx 154; LARGE-PIC-NEXT: movq (%rax,%rcx), %rax 155; LARGE-PIC-NEXT: retq 156 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @extern_data, i64 0, i64 0) 157} 158 159define dso_local i32 @load_global_data() #0 { 160; SMALL-STATIC-LABEL: load_global_data: 161; SMALL-STATIC: # %bb.0: 162; SMALL-STATIC-NEXT: movl global_data+8(%rip), %eax 163; SMALL-STATIC-NEXT: retq 164; 165; MEDIUM-STATIC-LABEL: load_global_data: 166; MEDIUM-STATIC: # %bb.0: 167; MEDIUM-STATIC-NEXT: movabsq $global_data, %rax 168; MEDIUM-STATIC-NEXT: movl 8(%rax), %eax 169; MEDIUM-STATIC-NEXT: retq 170; 171; LARGE-STATIC-LABEL: load_global_data: 172; LARGE-STATIC: # %bb.0: 173; LARGE-STATIC-NEXT: movabsq $global_data, %rax 174; LARGE-STATIC-NEXT: movl 8(%rax), %eax 175; LARGE-STATIC-NEXT: retq 176; 177; SMALL-PIC-LABEL: load_global_data: 178; SMALL-PIC: # %bb.0: 179; SMALL-PIC-NEXT: movl global_data+8(%rip), %eax 180; SMALL-PIC-NEXT: retq 181; 182; MEDIUM-PIC-LABEL: load_global_data: 183; MEDIUM-PIC: # %bb.0: 184; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax 185; MEDIUM-PIC-NEXT: movabsq $global_data@GOTOFF, %rcx 186; MEDIUM-PIC-NEXT: movl 8(%rax,%rcx), %eax 187; MEDIUM-PIC-NEXT: retq 188; 189; LARGE-PIC-LABEL: load_global_data: 190; LARGE-PIC: # %bb.0: 191; LARGE-PIC-NEXT: .Ltmp3: 192; LARGE-PIC-NEXT: leaq .Ltmp3(%rip), %rax 193; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp3, %rcx 194; LARGE-PIC-NEXT: addq %rcx, %rax 195; LARGE-PIC-NEXT: movabsq $global_data@GOTOFF, %rcx 196; LARGE-PIC-NEXT: movl 8(%rax,%rcx), %eax 197; LARGE-PIC-NEXT: retq 198 %rv = load i32, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @global_data, i64 0, i64 2) 199 ret i32 %rv 200} 201 202define dso_local i32 @load_extern_data() #0 { 203; SMALL-STATIC-LABEL: load_extern_data: 204; SMALL-STATIC: # %bb.0: 205; SMALL-STATIC-NEXT: movl extern_data+8(%rip), %eax 206; SMALL-STATIC-NEXT: retq 207; 208; MEDIUM-STATIC-LABEL: load_extern_data: 209; MEDIUM-STATIC: # %bb.0: 210; MEDIUM-STATIC-NEXT: movabsq $extern_data, %rax 211; MEDIUM-STATIC-NEXT: movl 8(%rax), %eax 212; MEDIUM-STATIC-NEXT: retq 213; 214; LARGE-STATIC-LABEL: load_extern_data: 215; LARGE-STATIC: # %bb.0: 216; LARGE-STATIC-NEXT: movabsq $extern_data, %rax 217; LARGE-STATIC-NEXT: movl 8(%rax), %eax 218; LARGE-STATIC-NEXT: retq 219; 220; SMALL-PIC-LABEL: load_extern_data: 221; SMALL-PIC: # %bb.0: 222; SMALL-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax 223; SMALL-PIC-NEXT: movl 8(%rax), %eax 224; SMALL-PIC-NEXT: retq 225; 226; MEDIUM-PIC-LABEL: load_extern_data: 227; MEDIUM-PIC: # %bb.0: 228; MEDIUM-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax 229; MEDIUM-PIC-NEXT: movl 8(%rax), %eax 230; MEDIUM-PIC-NEXT: retq 231; 232; LARGE-PIC-LABEL: load_extern_data: 233; LARGE-PIC: # %bb.0: 234; LARGE-PIC-NEXT: .Ltmp4: 235; LARGE-PIC-NEXT: leaq .Ltmp4(%rip), %rax 236; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp4, %rcx 237; LARGE-PIC-NEXT: addq %rcx, %rax 238; LARGE-PIC-NEXT: movabsq $extern_data@GOT, %rcx 239; LARGE-PIC-NEXT: movq (%rax,%rcx), %rax 240; LARGE-PIC-NEXT: movl 8(%rax), %eax 241; LARGE-PIC-NEXT: retq 242 %rv = load i32, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @extern_data, i64 0, i64 2) 243 ret i32 %rv 244} 245 246define dso_local void @global_fn() #0 { 247; CHECK-LABEL: global_fn: 248; CHECK: # %bb.0: 249; CHECK-NEXT: retq 250 ret void 251} 252 253define internal void @static_fn() #0 { 254; CHECK-LABEL: static_fn: 255; CHECK: # %bb.0: 256; CHECK-NEXT: retq 257 ret void 258} 259 260declare void @extern_fn() 261 262define dso_local void ()* @lea_static_fn() #0 { 263; SMALL-STATIC-LABEL: lea_static_fn: 264; SMALL-STATIC: # %bb.0: 265; SMALL-STATIC-NEXT: movl $static_fn, %eax 266; SMALL-STATIC-NEXT: retq 267; 268; MEDIUM-STATIC-LABEL: lea_static_fn: 269; MEDIUM-STATIC: # %bb.0: 270; MEDIUM-STATIC-NEXT: movabsq $static_fn, %rax 271; MEDIUM-STATIC-NEXT: retq 272; 273; LARGE-STATIC-LABEL: lea_static_fn: 274; LARGE-STATIC: # %bb.0: 275; LARGE-STATIC-NEXT: movabsq $static_fn, %rax 276; LARGE-STATIC-NEXT: retq 277; 278; SMALL-PIC-LABEL: lea_static_fn: 279; SMALL-PIC: # %bb.0: 280; SMALL-PIC-NEXT: leaq static_fn(%rip), %rax 281; SMALL-PIC-NEXT: retq 282; 283; MEDIUM-PIC-LABEL: lea_static_fn: 284; MEDIUM-PIC: # %bb.0: 285; MEDIUM-PIC-NEXT: movabsq $static_fn, %rax 286; MEDIUM-PIC-NEXT: retq 287; 288; LARGE-PIC-LABEL: lea_static_fn: 289; LARGE-PIC: # %bb.0: 290; LARGE-PIC-NEXT: .Ltmp5: 291; LARGE-PIC-NEXT: leaq .Ltmp5(%rip), %rcx 292; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp5, %rax 293; LARGE-PIC-NEXT: addq %rax, %rcx 294; LARGE-PIC-NEXT: movabsq $static_fn@GOTOFF, %rax 295; LARGE-PIC-NEXT: addq %rcx, %rax 296; LARGE-PIC-NEXT: retq 297 ret void ()* @static_fn 298} 299 300define dso_local void ()* @lea_global_fn() #0 { 301; SMALL-STATIC-LABEL: lea_global_fn: 302; SMALL-STATIC: # %bb.0: 303; SMALL-STATIC-NEXT: movl $global_fn, %eax 304; SMALL-STATIC-NEXT: retq 305; 306; MEDIUM-STATIC-LABEL: lea_global_fn: 307; MEDIUM-STATIC: # %bb.0: 308; MEDIUM-STATIC-NEXT: movabsq $global_fn, %rax 309; MEDIUM-STATIC-NEXT: retq 310; 311; LARGE-STATIC-LABEL: lea_global_fn: 312; LARGE-STATIC: # %bb.0: 313; LARGE-STATIC-NEXT: movabsq $global_fn, %rax 314; LARGE-STATIC-NEXT: retq 315; 316; SMALL-PIC-LABEL: lea_global_fn: 317; SMALL-PIC: # %bb.0: 318; SMALL-PIC-NEXT: leaq global_fn(%rip), %rax 319; SMALL-PIC-NEXT: retq 320; 321; MEDIUM-PIC-LABEL: lea_global_fn: 322; MEDIUM-PIC: # %bb.0: 323; MEDIUM-PIC-NEXT: movabsq $global_fn, %rax 324; MEDIUM-PIC-NEXT: retq 325; 326; LARGE-PIC-LABEL: lea_global_fn: 327; LARGE-PIC: # %bb.0: 328; LARGE-PIC-NEXT: .Ltmp6: 329; LARGE-PIC-NEXT: leaq .Ltmp6(%rip), %rcx 330; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp6, %rax 331; LARGE-PIC-NEXT: addq %rax, %rcx 332; LARGE-PIC-NEXT: movabsq $global_fn@GOTOFF, %rax 333; LARGE-PIC-NEXT: addq %rcx, %rax 334; LARGE-PIC-NEXT: retq 335 ret void ()* @global_fn 336} 337 338define dso_local void ()* @lea_extern_fn() #0 { 339; SMALL-STATIC-LABEL: lea_extern_fn: 340; SMALL-STATIC: # %bb.0: 341; SMALL-STATIC-NEXT: movl $extern_fn, %eax 342; SMALL-STATIC-NEXT: retq 343; 344; MEDIUM-STATIC-LABEL: lea_extern_fn: 345; MEDIUM-STATIC: # %bb.0: 346; MEDIUM-STATIC-NEXT: movabsq $extern_fn, %rax 347; MEDIUM-STATIC-NEXT: retq 348; 349; LARGE-STATIC-LABEL: lea_extern_fn: 350; LARGE-STATIC: # %bb.0: 351; LARGE-STATIC-NEXT: movabsq $extern_fn, %rax 352; LARGE-STATIC-NEXT: retq 353; 354; SMALL-PIC-LABEL: lea_extern_fn: 355; SMALL-PIC: # %bb.0: 356; SMALL-PIC-NEXT: movq extern_fn@GOTPCREL(%rip), %rax 357; SMALL-PIC-NEXT: retq 358; 359; MEDIUM-PIC-LABEL: lea_extern_fn: 360; MEDIUM-PIC: # %bb.0: 361; MEDIUM-PIC-NEXT: movq extern_fn@GOTPCREL(%rip), %rax 362; MEDIUM-PIC-NEXT: retq 363; 364; LARGE-PIC-LABEL: lea_extern_fn: 365; LARGE-PIC: # %bb.0: 366; LARGE-PIC-NEXT: .Ltmp7: 367; LARGE-PIC-NEXT: leaq .Ltmp7(%rip), %rax 368; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.Ltmp7, %rcx 369; LARGE-PIC-NEXT: addq %rcx, %rax 370; LARGE-PIC-NEXT: movabsq $extern_fn@GOT, %rcx 371; LARGE-PIC-NEXT: movq (%rax,%rcx), %rax 372; LARGE-PIC-NEXT: retq 373 ret void ()* @extern_fn 374} 375 376attributes #0 = { noinline nounwind uwtable } 377 378!llvm.module.flags = !{!0, !1, !2} 379!llvm.ident = !{!3} 380 381!0 = !{i32 1, !"wchar_size", i32 4} 382!1 = !{i32 7, !"PIC Level", i32 2} 383!2 = !{i32 7, !"PIE Level", i32 2} 384!3 = !{!"clang version 7.0.0 "} 385