Home | History | Annotate | Download | only in GlobalOpt
      1 ; RUN: opt < %s -S -globalopt | FileCheck %s
      2 
      3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
      4 
      5 @.str91250 = global [3 x i8] zeroinitializer
      6 
      7 ; CHECK: @A = global i1 false
      8 @A = global i1 icmp ne (i64 sub nsw (i64 ptrtoint (i8* getelementptr inbounds ([3 x i8]* @.str91250, i64 0, i64 1) to i64), i64 ptrtoint ([3 x i8]* @.str91250 to i64)), i64 1)
      9 
     10 ; PR11352
     11 
     12 @xs = global [2 x i32] zeroinitializer, align 4
     13 ; CHECK: @xs = global [2 x i32] [i32 1, i32 1]
     14 
     15 ; PR12642
     16 %PR12642.struct = type { i8 }
     17 @PR12642.s = global <{}> zeroinitializer, align 1
     18 @PR12642.p = constant %PR12642.struct* bitcast (i8* getelementptr (i8* bitcast (<{}>* @PR12642.s to i8*), i64 1) to %PR12642.struct*), align 8
     19 
     20 define internal void @test1() {
     21 entry:
     22   store i32 1, i32* getelementptr inbounds ([2 x i32]* @xs, i64 0, i64 0)
     23   %0 = load i32* getelementptr inbounds ([2 x i32]* @xs, i32 0, i64 0), align 4
     24   store i32 %0, i32* getelementptr inbounds ([2 x i32]* @xs, i64 0, i64 1)
     25   ret void
     26 }
     27 
     28 ; PR12060
     29 
     30 %closure = type { i32 }
     31 
     32 @f = internal global %closure zeroinitializer, align 4
     33 @m = global i32 0, align 4
     34 ; CHECK-NOT: @f
     35 ; CHECK: @m = global i32 13
     36 
     37 define internal i32 @test2_helper(%closure* %this, i32 %b) {
     38 entry:
     39   %0 = getelementptr inbounds %closure* %this, i32 0, i32 0
     40   %1 = load i32* %0, align 4
     41   %add = add nsw i32 %1, %b
     42   ret i32 %add
     43 }
     44 
     45 define internal void @test2() {
     46 entry:
     47   store i32 4, i32* getelementptr inbounds (%closure* @f, i32 0, i32 0)
     48   %call = call i32 @test2_helper(%closure* @f, i32 9)
     49   store i32 %call, i32* @m, align 4
     50   ret void
     51 }
     52 
     53 ; PR19955
     54 
     55 @dllimportptr = global i32* null, align 4
     56 ; CHECK: @dllimportptr = global i32* null, align 4
     57 @dllimportvar = external dllimport global i32
     58 define internal void @test3() {
     59 entry:
     60   store i32* @dllimportvar, i32** @dllimportptr, align 4
     61   ret void
     62 }
     63 
     64 @dllexportptr = global i32* null, align 4
     65 ; CHECK: @dllexportptr = global i32* @dllexportvar, align 4
     66 @dllexportvar = dllexport global i32 0, align 4
     67 ; CHECK: @dllexportvar = dllexport global i32 20, align 4
     68 define internal void @test4() {
     69 entry:
     70   store i32 20, i32* @dllexportvar, align 4
     71   store i32* @dllexportvar, i32** @dllexportptr, align 4
     72   ret void
     73 }
     74 
     75 @threadlocalptr = global i32* null, align 4
     76 ; CHECK: @threadlocalptr = global i32* null, align 4
     77 @threadlocalvar = external thread_local global i32
     78 define internal void @test5() {
     79 entry:
     80   store i32* @threadlocalvar, i32** @threadlocalptr, align 4
     81   ret void
     82 }
     83 
     84 @llvm.global_ctors = appending constant
     85   [5 x { i32, void ()* }]
     86   [{ i32, void ()* } { i32 65535, void ()* @test1 },
     87    { i32, void ()* } { i32 65535, void ()* @test2 },
     88    { i32, void ()* } { i32 65535, void ()* @test3 },
     89    { i32, void ()* } { i32 65535, void ()* @test4 },
     90    { i32, void ()* } { i32 65535, void ()* @test5 }]
     91