61 lines · plain
1; Check that we promote constant object in the source module and import it2; even when it is referenced in some other GV initializer and/or is used3; by store instructions.4; RUN: opt -thinlto-bc %s -o %t1.bc5; RUN: opt -thinlto-bc %p/Inputs/import-constant.ll -o %t2.bc6; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t-out \7; RUN: -import-constants-with-refs \8; RUN: -r=%t1.bc,main,plx \9; RUN: -r=%t1.bc,_Z6getObjv,l \10; RUN: -r=%t2.bc,_Z6getObjv,pl \11; RUN: -r=%t2.bc,val,pl \12; RUN: -r=%t2.bc,outer,pl13; RUN: llvm-dis %t-out.2.1.promote.bc -o - | FileCheck %s --check-prefix=PROMOTE14; RUN: llvm-dis %t-out.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT15; RUN: llvm-dis %t-out.1.4.opt.bc -o - | FileCheck %s --check-prefix=OPT16 17; Check when importing references is prohibited18; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t-out-norefs \19; RUN: -import-constants-with-refs=false \20; RUN: -r=%t1.bc,main,plx \21; RUN: -r=%t1.bc,_Z6getObjv,l \22; RUN: -r=%t2.bc,_Z6getObjv,pl \23; RUN: -r=%t2.bc,val,pl \24; RUN: -r=%t2.bc,outer,pl25; RUN: llvm-dis %t-out-norefs.1.3.import.bc -o - | FileCheck %s --check-prefix=NOREFS26 27; Check that variable has been promoted in the source module28; PROMOTE: @_ZL3Obj.llvm.{{.*}} = hidden constant %struct.S { i32 4, i32 8, ptr @val }29 30; @outer is a write-only variable, so it's been converted to zeroinitializer.31; IMPORT: @val = available_externally global i32 4232; IMPORT-NEXT: @_ZL3Obj.llvm.{{.*}} = available_externally hidden constant %struct.S { i32 4, i32 8, ptr @val }33; IMPORT-NEXT: @outer = internal local_unnamed_addr global %struct.Q zeroinitializer34 35; @outer is a write-only variable that's stored to once, so the store and the global can be removed.36; OPT-NOT: @outer37 38; OPT: define dso_local noundef i32 @main()39; OPT-NEXT: entry:40; OPT-NEXT: ret i32 1241 42; NOREFS: @_ZL3Obj.llvm.{{.*}} = external hidden constant %struct.S43; NOREFS-NEXT: @outer = internal local_unnamed_addr global %struct.Q zeroinitializer44 45target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"46target triple = "x86_64-unknown-linux-gnu"47 48%struct.S = type { i32, i32, ptr }49 50define dso_local i32 @main() local_unnamed_addr {51entry:52 %call = tail call ptr @_Z6getObjv()53 %0 = load i32, ptr %call, align 854 %v = getelementptr inbounds %struct.S, ptr %call, i64 0, i32 155 %1 = load i32, ptr %v, align 456 %add = add nsw i32 %1, %057 ret i32 %add58}59 60declare dso_local ptr @_Z6getObjv() local_unnamed_addr61