diff --git a/llvm/test/Transforms/DeadStoreElimination/simple.ll b/llvm/test/Transforms/DeadStoreElimination/simple.ll index dd1443e77e4d..2ffe0539098e 100644 --- a/llvm/test/Transforms/DeadStoreElimination/simple.ll +++ b/llvm/test/Transforms/DeadStoreElimination/simple.ll @@ -3,7 +3,7 @@ target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:1 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind -declare i8* @llvm.init.trampoline(i8*, i8*, i8*) +declare void @llvm.init.trampoline(i8*, i8*, i8*) define void @test1(i32* %Q, i32* %P) { %DEAD = load i32, i32* %Q @@ -132,7 +132,7 @@ define void @test11() { %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1] ; CHECK-NOT: alloca %cast = getelementptr [10 x i8], [10 x i8]* %storage, i32 0, i32 0 ; [#uses=1] - %tramp = call i8* @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1] + call void @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1] ; CHECK-NOT: trampoline ret void ; CHECK: ret void diff --git a/llvm/test/Transforms/GlobalOpt/blockaddress.ll b/llvm/test/Transforms/GlobalOpt/blockaddress.ll index f7f830869b84..12e09fcd4815 100644 --- a/llvm/test/Transforms/GlobalOpt/blockaddress.ll +++ b/llvm/test/Transforms/GlobalOpt/blockaddress.ll @@ -13,6 +13,9 @@ define void @f() { } define void @g() { +entry: + br label %here + ; CHECK-LABEL: @g( here: diff --git a/llvm/test/Transforms/IndVarSimplify/2011-11-01-lftrptr.ll b/llvm/test/Transforms/IndVarSimplify/2011-11-01-lftrptr.ll index a0b1e84a8616..402ae8cc05d0 100644 --- a/llvm/test/Transforms/IndVarSimplify/2011-11-01-lftrptr.ll +++ b/llvm/test/Transforms/IndVarSimplify/2011-11-01-lftrptr.ll @@ -31,7 +31,8 @@ loop: br i1 %cmp, label %loop, label %exit exit: - ret i8 %snext + %ret = phi i8 [0, %loopguard], [%snext, %loop] + ret i8 %ret } ; CHECK-LABEL: @testptrptr( @@ -56,7 +57,8 @@ loop: br i1 %cmp, label %loop, label %exit exit: - ret i8 %snext + %ret = phi i8 [0, %loopguard], [%snext, %loop] + ret i8 %ret } ; CHECK-LABEL: @testnullptrint( @@ -86,7 +88,8 @@ loop: br i1 %cmp, label %loop, label %exit exit: - ret i8 %snext + %ret = phi i8 [0, %loopguard], [%snext, %loop] + ret i8 %ret } ; CHECK-LABEL: @testptrint( @@ -116,7 +119,8 @@ loop: br i1 %cmp, label %loop, label %exit exit: - ret i8 %snext + %ret = phi i8 [0, %loopguard], [%snext, %loop] + ret i8 %ret } ; IV and BECount have two different pointer types here. diff --git a/llvm/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll b/llvm/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll index b8ca56050dca..df0b472bb2a5 100644 --- a/llvm/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll +++ b/llvm/test/Transforms/Inline/2003-09-22-PHINodeInlineFail.ll @@ -9,7 +9,7 @@ LongJmpBlkPost: ret i32 0 LongJmpBlkPre: - %i.3 = phi i32 [ 0, %entry ], [ 0, %entry ] ; [#uses=0] + %i.3 = phi i32 [ 0, %entry ] %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 cleanup ret i32 0 diff --git a/llvm/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll b/llvm/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll index 9af93325f142..d5416a205979 100644 --- a/llvm/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll +++ b/llvm/test/Transforms/Inline/2003-09-22-PHINodesInExceptionDest.ll @@ -9,7 +9,7 @@ Call2Invoke: ; preds = %entry br label %exit LongJmpBlkPre: ; preds = %Call2Invoke, %entry - %i.3 = phi i32 [ 0, %entry ], [ 0, %Call2Invoke ] ; [#uses=0] + %i.3 = phi i32 [ 0, %entry ] %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 cleanup br label %exit diff --git a/llvm/test/Transforms/InstCombine/call-intrinsics.ll b/llvm/test/Transforms/InstCombine/call-intrinsics.ll index f9d108058063..3e37a71e1bf6 100644 --- a/llvm/test/Transforms/InstCombine/call-intrinsics.ll +++ b/llvm/test/Transforms/InstCombine/call-intrinsics.ll @@ -3,17 +3,17 @@ @X = global i8 0 ; [#uses=3] @Y = global i8 12 ; [#uses=2] -declare void @llvm.memmove.i32(i8*, i8*, i32, i32) +declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1) -declare void @llvm.memcpy.i32(i8*, i8*, i32, i32) +declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1) -declare void @llvm.memset.i32(i8*, i8, i32, i32) +declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1) define void @zero_byte_test() { ; These process zero bytes, so they are a noop. - call void @llvm.memmove.i32( i8* @X, i8* @Y, i32 0, i32 100 ) - call void @llvm.memcpy.i32( i8* @X, i8* @Y, i32 0, i32 100 ) - call void @llvm.memset.i32( i8* @X, i8 123, i32 0, i32 100 ) + call void @llvm.memmove.p0i8.p0i8.i32( i8* @X, i8* @Y, i32 0, i32 128, i1 false ) + call void @llvm.memcpy.p0i8.p0i8.i32( i8* @X, i8* @Y, i32 0, i32 128, i1 false ) + call void @llvm.memset.p0i8.i32( i8* @X, i8 123, i32 0, i32 128, i1 false ) ret void } diff --git a/llvm/test/Transforms/InstCombine/objsize-noverify.ll b/llvm/test/Transforms/InstCombine/objsize-noverify.ll new file mode 100644 index 000000000000..7e469bd25282 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/objsize-noverify.ll @@ -0,0 +1,43 @@ +; Test objectsize bounds checking that won't verify until after -instcombine. +; RUN: opt < %s -disable-verify -instcombine -S | opt -S | FileCheck %s +; We need target data to get the sizes of the arrays and structures. +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" + +declare i32 @llvm.objectsize.i32.p0i8(i8*, i1) nounwind readonly + +; CHECK-LABEL: @PR13390( +define i32 @PR13390(i1 %bool, i8* %a) { +entry: + %cond = or i1 %bool, true + br i1 %cond, label %return, label %xpto + +xpto: + %select = select i1 %bool, i8* %select, i8* %a + %select2 = select i1 %bool, i8* %a, i8* %select2 + %0 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select, i1 true) + %1 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select2, i1 true) + %2 = add i32 %0, %1 +; CHECK: ret i32 undef + ret i32 %2 + +return: + ret i32 42 +} + +; CHECK-LABEL: @PR13621( +define i32 @PR13621(i1 %bool) nounwind { +entry: + %cond = or i1 %bool, true + br i1 %cond, label %return, label %xpto + +; technically reachable, but this malformed IR may appear as a result of constant propagation +xpto: + %gep2 = getelementptr i8, i8* %gep, i32 1 + %gep = getelementptr i8, i8* %gep2, i32 1 + %o = call i32 @llvm.objectsize.i32.p0i8(i8* %gep, i1 true) +; CHECK: ret i32 undef + ret i32 %o + +return: + ret i32 7 +} diff --git a/llvm/test/Transforms/InstCombine/objsize.ll b/llvm/test/Transforms/InstCombine/objsize.ll index 3125458549d6..335a816e9ece 100644 --- a/llvm/test/Transforms/InstCombine/objsize.ll +++ b/llvm/test/Transforms/InstCombine/objsize.ll @@ -219,43 +219,6 @@ define i32 @test13(i8** %esc) { ret i32 %1 } -; CHECK-LABEL: @PR13390( -define i32 @PR13390(i1 %bool, i8* %a) { -entry: - %cond = or i1 %bool, true - br i1 %cond, label %return, label %xpto - -xpto: - %select = select i1 %bool, i8* %select, i8* %a - %select2 = select i1 %bool, i8* %a, i8* %select2 - %0 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select, i1 true) - %1 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select2, i1 true) - %2 = add i32 %0, %1 -; CHECK: ret i32 undef - ret i32 %2 - -return: - ret i32 42 -} - -; CHECK-LABEL: @PR13621( -define i32 @PR13621(i1 %bool) nounwind { -entry: - %cond = or i1 %bool, true - br i1 %cond, label %return, label %xpto - -; technically reachable, but this malformed IR may appear as a result of constant propagation -xpto: - %gep2 = getelementptr i8, i8* %gep, i32 1 - %gep = getelementptr i8, i8* %gep2, i32 1 - %o = call i32 @llvm.objectsize.i32.p0i8(i8* %gep, i1 true) -; CHECK: ret i32 undef - ret i32 %o - -return: - ret i32 7 -} - @globalalias = internal alias [60 x i8]* @a ; CHECK-LABEL: @test18( diff --git a/llvm/test/Transforms/InstCombine/select-crash-noverify.ll b/llvm/test/Transforms/InstCombine/select-crash-noverify.ll new file mode 100644 index 000000000000..4a366aa8fb83 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/select-crash-noverify.ll @@ -0,0 +1,19 @@ +; RUN: opt < %s -disable-verify -instcombine -S | opt -S | FileCheck %s +; Formerly crashed, PR8490. + +; CHECK-LABEL: @test3( +define i32 @test3(i1 %bool, i32 %a) { +entry: + %cond = or i1 %bool, true + br i1 %cond, label %return, label %xpto + +; technically reachable, but this malformed IR may appear as a result of constant propagation +xpto: + %select = select i1 %bool, i32 %a, i32 %select + %select2 = select i1 %bool, i32 %select2, i32 %a + %sum = add i32 %select, %select2 + ret i32 %sum + +return: + ret i32 7 +} diff --git a/llvm/test/Transforms/InstCombine/select-crash.ll b/llvm/test/Transforms/InstCombine/select-crash.ll index 77446cd8ba02..991635b63aa8 100644 --- a/llvm/test/Transforms/InstCombine/select-crash.ll +++ b/llvm/test/Transforms/InstCombine/select-crash.ll @@ -30,20 +30,3 @@ define <4 x float> @foo(i1 %b, <4 x float> %x, <4 x float> %y, <4 x float> %z) { %sel = select i1 %b, <4 x float> %a, <4 x float> %sub ret <4 x float> %sel } - -; CHECK-LABEL: @test3( -define i32 @test3(i1 %bool, i32 %a) { -entry: - %cond = or i1 %bool, true - br i1 %cond, label %return, label %xpto - -; technically reachable, but this malformed IR may appear as a result of constant propagation -xpto: - %select = select i1 %bool, i32 %a, i32 %select - %select2 = select i1 %bool, i32 %select2, i32 %a - %sum = add i32 %select, %select2 - ret i32 %sum - -return: - ret i32 7 -} diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll index e4cc6f58c05a..ef122c92092d 100644 --- a/llvm/test/Transforms/InstCombine/select.ll +++ b/llvm/test/Transforms/InstCombine/select.ll @@ -423,11 +423,11 @@ jump: %c = or i1 false, false br label %ret ret: - %a = phi i1 [true, %jump], [%c, %entry] - %b = select i1 %a, i32 10, i32 20 + %a = phi i1 [true, %entry], [%c, %jump] + %b = select i1 %a, i32 20, i32 10 ret i32 %b ; CHECK-LABEL: @test26( -; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ] +; CHECK: %a = phi i32 [ 20, %entry ], [ 10, %jump ] ; CHECK-NEXT: ret i32 %a } diff --git a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll index 8a8b834fa9e7..4245c7a3c134 100644 --- a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll +++ b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll @@ -350,19 +350,19 @@ define <8 x float> @test_vpermilvar_ps_256(<8 x float> %v) { ret <8 x float> %a } -declare <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double>, <2 x i32>) +declare <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double>, <2 x i64>) define <2 x double> @test_vpermilvar_pd(<2 x double> %v) { ; CHECK-LABEL: @test_vpermilvar_pd( ; CHECK: shufflevector <2 x double> %v, <2 x double> undef, <2 x i32> - %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i32> ) + %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i64> ) ret <2 x double> %a } -declare <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double>, <4 x i32>) +declare <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double>, <4 x i64>) define <4 x double> @test_vpermilvar_pd_256(<4 x double> %v) { ; CHECK-LABEL: @test_vpermilvar_pd_256( ; CHECK: shufflevector <4 x double> %v, <4 x double> undef, <4 x i32> - %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i32> ) + %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i64> ) ret <4 x double> %a } @@ -383,14 +383,14 @@ define <8 x float> @test_vpermilvar_ps_256_zero(<8 x float> %v) { define <2 x double> @test_vpermilvar_pd_zero(<2 x double> %v) { ; CHECK-LABEL: @test_vpermilvar_pd_zero( ; CHECK: shufflevector <2 x double> %v, <2 x double> undef, <2 x i32> zeroinitializer - %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i32> zeroinitializer) + %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i64> zeroinitializer) ret <2 x double> %a } define <4 x double> @test_vpermilvar_pd_256_zero(<4 x double> %v) { ; CHECK-LABEL: @test_vpermilvar_pd_256_zero( ; CHECK: shufflevector <4 x double> %v, <4 x double> undef, <4 x i32> - %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i32> zeroinitializer) + %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i64> zeroinitializer) ret <4 x double> %a } diff --git a/llvm/test/Transforms/LoopSimplify/dup-preds.ll b/llvm/test/Transforms/LoopSimplify/dup-preds.ll index 3d1f1499b11c..c9253fa51a65 100644 --- a/llvm/test/Transforms/LoopSimplify/dup-preds.ll +++ b/llvm/test/Transforms/LoopSimplify/dup-preds.ll @@ -28,7 +28,7 @@ for.body305: ; preds = %for.body305, %if.th br label %for.body305 for.body344: ; preds = %for.body344, %for.body276.lr.ph, %for.body276.lr.ph - %indvar = phi i64 [ %indvar.next, %for.body344 ], [ 0, %for.body276.lr.ph ] + %indvar = phi i64 [ %indvar.next, %for.body344 ], [ 0, %for.body276.lr.ph ], [ 0, %for.body276.lr.ph ] %indvars.iv552 = phi i64 [ %indvars.iv.next553, %for.body344 ], [ 0, %for.body276.lr.ph ], [ 0, %for.body276.lr.ph ] %indvars.iv.next553 = add nuw nsw i64 %indvars.iv552, 1 %indvar.next = add i64 %indvar, 1 diff --git a/llvm/test/Transforms/LowerInvoke/2003-12-10-Crash.ll b/llvm/test/Transforms/LowerInvoke/2003-12-10-Crash.ll index 31f3d42225ab..fca8e868018a 100644 --- a/llvm/test/Transforms/LowerInvoke/2003-12-10-Crash.ll +++ b/llvm/test/Transforms/LowerInvoke/2003-12-10-Crash.ll @@ -15,8 +15,11 @@ invoke_cont.0: ; preds = %then to label %try_exit unwind label %try_catch try_catch: ; preds = %invoke_cont.0, %then %__tmp.0 = phi i32* [ null, %invoke_cont.0 ], [ null, %then ] ; [#uses=0] + %res = landingpad { i8* } personality i32 (...)* @__gxx_personality_v0 + cleanup ret void try_exit: ; preds = %invoke_cont.0 ret void } +declare i32 @__gxx_personality_v0(...) diff --git a/llvm/test/Transforms/ObjCARC/move-and-merge-autorelease.ll b/llvm/test/Transforms/ObjCARC/move-and-merge-autorelease.ll index 5d19f355be32..0a68541d9350 100644 --- a/llvm/test/Transforms/ObjCARC/move-and-merge-autorelease.ll +++ b/llvm/test/Transforms/ObjCARC/move-and-merge-autorelease.ll @@ -99,9 +99,9 @@ bb81: ; preds = %bb, %bb76 %tmp10.1 = phi %0* [ %tmp10.0, %bb76 ], [ null, %bb ] %tmp83 = bitcast %0* %tmp10.1 to i8* %tmp84 = call i8* @objc_retain(i8* %tmp83) nounwind - %tmp88 = bitcast i8* %tmp87 to %0* call void @objc_release(i8* %tmp23) nounwind %tmp87 = call i8* @objc_autorelease(i8* %tmp84) nounwind + %tmp88 = bitcast i8* %tmp87 to %0* %tmp92 = bitcast %0* %tmp10.1 to i8* call void @objc_release(i8* %tmp92) nounwind ret %0* %tmp88 diff --git a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll index 22b144b5cb80..8718c552c693 100644 --- a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll +++ b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll @@ -22,11 +22,15 @@ entry: invoke void @test2( ) to label %N unwind label %U U: + %res = landingpad { i8* } personality i32 (...)* @__gxx_personality_v0 + cleanup unreachable N: ret void } +declare i32 @__gxx_personality_v0(...) + define i32 @test3(i32 %v) { ; CHECK-LABEL: @test3( ; CHECK: entry: diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 55a45dca2e8c..fa8d2688dd2e 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -25,6 +25,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Pass.h" @@ -225,6 +226,14 @@ static int compileModule(char **argv, LLVMContext &Context) { return 1; } + // Verify module immediately to catch problems before doInitialization() is + // called on any passes. + if (!NoVerify && verifyModule(*M, &errs())) { + errs() << argv[0] << ": " << InputFilename + << ": error: does not verify\n"; + return 1; + } + // If we are supposed to override the target triple, do so now. if (!TargetTriple.empty()) M->setTargetTriple(Triple::normalize(TargetTriple)); diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index c1e120af5407..86fbed700365 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -25,6 +25,7 @@ #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/CodeGen/CommandFlags.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfo.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" @@ -345,6 +346,18 @@ int main(int argc, char **argv) { return 1; } + // Strip debug info before running the verifier. + if (StripDebug) + StripDebugInfo(*M); + + // Immediately run the verifier to catch any problems before starting up the + // pass pipelines. Otherwise we can crash on broken code during + // doInitialization(). + if (!NoVerify && verifyModule(*M, &errs())) { + errs() << argv[0] << ": " << InputFilename << ": error: does not verify\n"; + return 1; + } + // If we are supposed to override the target triple, do so now. if (!TargetTriple.empty()) M->setTargetTriple(Triple::normalize(TargetTriple)); @@ -449,10 +462,6 @@ int main(int argc, char **argv) { NoOutput = true; } - // If the -strip-debug command line option was specified, add it. - if (StripDebug) - addPass(Passes, createStripSymbolsPass(true)); - // Create a new optimization pass for each one specified on the command line for (unsigned i = 0; i < PassList.size(); ++i) { if (StandardLinkOpts &&