Index: test/tools/llvm-lto/thinlto-opt.ll =================================================================== --- /dev/null +++ test/tools/llvm-lto/thinlto-opt.ll @@ -0,0 +1,17 @@ +; Test that -O works with ThinLTO + +; RUN: opt -module-summary %s -o %t.o +; RUN: llvm-lto -O0 -thinlto-action=optimize -o %t.O0 %t.o +; RUN: llvm-lto -O3 -thinlto-action=optimize -o %t.O3 %t.o +; RUN: llvm-dis %t.O0 -o - | FileCheck %s --check-prefix=O0 +; RUN: llvm-dis %t.O3 -o - | FileCheck %s --check-prefix=O3 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f() { +; O0: %dead = +; O3-NOT: %dead = + %dead = add i32 1, 1 + ret void +} Index: tools/llvm-lto/llvm-lto.cpp =================================================================== --- tools/llvm-lto/llvm-lto.cpp +++ tools/llvm-lto/llvm-lto.cpp @@ -484,6 +484,7 @@ ThinGenerator.setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles); ThinGenerator.setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes); ThinGenerator.setFreestanding(EnableFreestanding); + ThinGenerator.setOptLevel(OptLevel - '0'); // Add all the exported symbols to the table of symbols to preserve. for (unsigned i = 0; i < ExportedSymbols.size(); ++i)