llvm.org GIT mirror llvm / de89228
Verifier: Call verifyModule() from llc and opt Change `llc` and `opt` to run `verifyModule()`. This ensures that we check the full module before `FunctionPass::doInitialization()` ever gets called (I was getting crashes in `DwarfDebug` instead of verifier failures when testing a WIP patch that checks operands of compile units). In `opt`, also move up debug-info-stripping so that it still runs before verification. There was a fair bit of broken code that was sitting in tree. Interestingly, some were cases of a `select` that referred to itself in `-instcombine` tests (apparently an intermediate result). I split them off to `*-noverify.ll` tests with RUN lines like this: opt < %s -S -disable-verify -instcombine | opt -S | FileCheck %s This avoids verifying the input file (so we can get the broken code into `-instcombine), but still verifies the output with a second call to `opt` (to verify that `-instcombine` will clean it up like it should). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233432 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
18 changed file(s) with 123 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
22
33 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
44 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
5 declare i8* @llvm.init.trampoline(i8*, i8*, i8*)
5 declare void @llvm.init.trampoline(i8*, i8*, i8*)
66
77 define void @test1(i32* %Q, i32* %P) {
88 %DEAD = load i32, i32* %Q
131131 %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
132132 ; CHECK-NOT: alloca
133133 %cast = getelementptr [10 x i8], [10 x i8]* %storage, i32 0, i32 0 ; [#uses=1]
134 %tramp = call i8* @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1]
134 call void @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1]
135135 ; CHECK-NOT: trampoline
136136 ret void
137137 ; CHECK: ret void
1212 }
1313
1414 define void @g() {
15 entry:
16 br label %here
17
1518 ; CHECK-LABEL: @g(
1619
1720 here:
3030 br i1 %cmp, label %loop, label %exit
3131
3232 exit:
33 ret i8 %snext
33 %ret = phi i8 [0, %loopguard], [%snext, %loop]
34 ret i8 %ret
3435 }
3536
3637 ; CHECK-LABEL: @testptrptr(
5556 br i1 %cmp, label %loop, label %exit
5657
5758 exit:
58 ret i8 %snext
59 %ret = phi i8 [0, %loopguard], [%snext, %loop]
60 ret i8 %ret
5961 }
6062
6163 ; CHECK-LABEL: @testnullptrint(
8587 br i1 %cmp, label %loop, label %exit
8688
8789 exit:
88 ret i8 %snext
90 %ret = phi i8 [0, %loopguard], [%snext, %loop]
91 ret i8 %ret
8992 }
9093
9194 ; CHECK-LABEL: @testptrint(
115118 br i1 %cmp, label %loop, label %exit
116119
117120 exit:
118 ret i8 %snext
121 %ret = phi i8 [0, %loopguard], [%snext, %loop]
122 ret i8 %ret
119123 }
120124
121125 ; IV and BECount have two different pointer types here.
88 ret i32 0
99
1010 LongJmpBlkPre:
11 %i.3 = phi i32 [ 0, %entry ], [ 0, %entry ] ; [#uses=0]
11 %i.3 = phi i32 [ 0, %entry ]
1212 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
1313 cleanup
1414 ret i32 0
88 br label %exit
99
1010 LongJmpBlkPre: ; preds = %Call2Invoke, %entry
11 %i.3 = phi i32 [ 0, %entry ], [ 0, %Call2Invoke ] ; [#uses=0]
11 %i.3 = phi i32 [ 0, %entry ]
1212 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
1313 cleanup
1414 br label %exit
22 @X = global i8 0 ; [#uses=3]
33 @Y = global i8 12 ; [#uses=2]
44
5 declare void @llvm.memmove.i32(i8*, i8*, i32, i32)
5 declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
66
7 declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
7 declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
88
9 declare void @llvm.memset.i32(i8*, i8, i32, i32)
9 declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1)
1010
1111 define void @zero_byte_test() {
1212 ; These process zero bytes, so they are a noop.
13 call void @llvm.memmove.i32( i8* @X, i8* @Y, i32 0, i32 100 )
14 call void @llvm.memcpy.i32( i8* @X, i8* @Y, i32 0, i32 100 )
15 call void @llvm.memset.i32( i8* @X, i8 123, i32 0, i32 100 )
13 call void @llvm.memmove.p0i8.p0i8.i32( i8* @X, i8* @Y, i32 0, i32 128, i1 false )
14 call void @llvm.memcpy.p0i8.p0i8.i32( i8* @X, i8* @Y, i32 0, i32 128, i1 false )
15 call void @llvm.memset.p0i8.i32( i8* @X, i8 123, i32 0, i32 128, i1 false )
1616 ret void
1717 }
1818
0 ; Test objectsize bounds checking that won't verify until after -instcombine.
1 ; RUN: opt < %s -disable-verify -instcombine -S | opt -S | FileCheck %s
2 ; We need target data to get the sizes of the arrays and structures.
3 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"
4
5 declare i32 @llvm.objectsize.i32.p0i8(i8*, i1) nounwind readonly
6
7 ; CHECK-LABEL: @PR13390(
8 define i32 @PR13390(i1 %bool, i8* %a) {
9 entry:
10 %cond = or i1 %bool, true
11 br i1 %cond, label %return, label %xpto
12
13 xpto:
14 %select = select i1 %bool, i8* %select, i8* %a
15 %select2 = select i1 %bool, i8* %a, i8* %select2
16 %0 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select, i1 true)
17 %1 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select2, i1 true)
18 %2 = add i32 %0, %1
19 ; CHECK: ret i32 undef
20 ret i32 %2
21
22 return:
23 ret i32 42
24 }
25
26 ; CHECK-LABEL: @PR13621(
27 define i32 @PR13621(i1 %bool) nounwind {
28 entry:
29 %cond = or i1 %bool, true
30 br i1 %cond, label %return, label %xpto
31
32 ; technically reachable, but this malformed IR may appear as a result of constant propagation
33 xpto:
34 %gep2 = getelementptr i8, i8* %gep, i32 1
35 %gep = getelementptr i8, i8* %gep2, i32 1
36 %o = call i32 @llvm.objectsize.i32.p0i8(i8* %gep, i1 true)
37 ; CHECK: ret i32 undef
38 ret i32 %o
39
40 return:
41 ret i32 7
42 }
218218 ret i32 %1
219219 }
220220
221 ; CHECK-LABEL: @PR13390(
222 define i32 @PR13390(i1 %bool, i8* %a) {
223 entry:
224 %cond = or i1 %bool, true
225 br i1 %cond, label %return, label %xpto
226
227 xpto:
228 %select = select i1 %bool, i8* %select, i8* %a
229 %select2 = select i1 %bool, i8* %a, i8* %select2
230 %0 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select, i1 true)
231 %1 = tail call i32 @llvm.objectsize.i32.p0i8(i8* %select2, i1 true)
232 %2 = add i32 %0, %1
233 ; CHECK: ret i32 undef
234 ret i32 %2
235
236 return:
237 ret i32 42
238 }
239
240 ; CHECK-LABEL: @PR13621(
241 define i32 @PR13621(i1 %bool) nounwind {
242 entry:
243 %cond = or i1 %bool, true
244 br i1 %cond, label %return, label %xpto
245
246 ; technically reachable, but this malformed IR may appear as a result of constant propagation
247 xpto:
248 %gep2 = getelementptr i8, i8* %gep, i32 1
249 %gep = getelementptr i8, i8* %gep2, i32 1
250 %o = call i32 @llvm.objectsize.i32.p0i8(i8* %gep, i1 true)
251 ; CHECK: ret i32 undef
252 ret i32 %o
253
254 return:
255 ret i32 7
256 }
257
258221 @globalalias = internal alias [60 x i8]* @a
259222
260223 ; CHECK-LABEL: @test18(
0 ; RUN: opt < %s -disable-verify -instcombine -S | opt -S | FileCheck %s
1 ; Formerly crashed, PR8490.
2
3 ; CHECK-LABEL: @test3(
4 define i32 @test3(i1 %bool, i32 %a) {
5 entry:
6 %cond = or i1 %bool, true
7 br i1 %cond, label %return, label %xpto
8
9 ; technically reachable, but this malformed IR may appear as a result of constant propagation
10 xpto:
11 %select = select i1 %bool, i32 %a, i32 %select
12 %select2 = select i1 %bool, i32 %select2, i32 %a
13 %sum = add i32 %select, %select2
14 ret i32 %sum
15
16 return:
17 ret i32 7
18 }
2929 %sel = select i1 %b, <4 x float> %a, <4 x float> %sub
3030 ret <4 x float> %sel
3131 }
32
33 ; CHECK-LABEL: @test3(
34 define i32 @test3(i1 %bool, i32 %a) {
35 entry:
36 %cond = or i1 %bool, true
37 br i1 %cond, label %return, label %xpto
38
39 ; technically reachable, but this malformed IR may appear as a result of constant propagation
40 xpto:
41 %select = select i1 %bool, i32 %a, i32 %select
42 %select2 = select i1 %bool, i32 %select2, i32 %a
43 %sum = add i32 %select, %select2
44 ret i32 %sum
45
46 return:
47 ret i32 7
48 }
422422 %c = or i1 false, false
423423 br label %ret
424424 ret:
425 %a = phi i1 [true, %jump], [%c, %entry]
426 %b = select i1 %a, i32 10, i32 20
425 %a = phi i1 [true, %entry], [%c, %jump]
426 %b = select i1 %a, i32 20, i32 10
427427 ret i32 %b
428428 ; CHECK-LABEL: @test26(
429 ; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
429 ; CHECK: %a = phi i32 [ 20, %entry ], [ 10, %jump ]
430430 ; CHECK-NEXT: ret i32 %a
431431 }
432432
349349 ret <8 x float> %a
350350 }
351351
352 declare <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double>, <2 x i32>)
352 declare <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double>, <2 x i64>)
353353 define <2 x double> @test_vpermilvar_pd(<2 x double> %v) {
354354 ; CHECK-LABEL: @test_vpermilvar_pd(
355355 ; CHECK: shufflevector <2 x double> %v, <2 x double> undef, <2 x i32>
356 %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i32> 0>)
356 %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i64> 0>)
357357 ret <2 x double> %a
358358 }
359359
360 declare <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double>, <4 x i32>)
360 declare <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double>, <4 x i64>)
361361 define <4 x double> @test_vpermilvar_pd_256(<4 x double> %v) {
362362 ; CHECK-LABEL: @test_vpermilvar_pd_256(
363363 ; CHECK: shufflevector <4 x double> %v, <4 x double> undef, <4 x i32>
364 %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i32> 0>)
364 %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i64> 0>)
365365 ret <4 x double> %a
366366 }
367367
382382 define <2 x double> @test_vpermilvar_pd_zero(<2 x double> %v) {
383383 ; CHECK-LABEL: @test_vpermilvar_pd_zero(
384384 ; CHECK: shufflevector <2 x double> %v, <2 x double> undef, <2 x i32> zeroinitializer
385 %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i32> zeroinitializer)
385 %a = tail call <2 x double> @llvm.x86.avx.vpermilvar.pd(<2 x double> %v, <2 x i64> zeroinitializer)
386386 ret <2 x double> %a
387387 }
388388
389389 define <4 x double> @test_vpermilvar_pd_256_zero(<4 x double> %v) {
390390 ; CHECK-LABEL: @test_vpermilvar_pd_256_zero(
391391 ; CHECK: shufflevector <4 x double> %v, <4 x double> undef, <4 x i32>
392 %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i32> zeroinitializer)
392 %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i64> zeroinitializer)
393393 ret <4 x double> %a
394394 }
395395
2727 br label %for.body305
2828
2929 for.body344: ; preds = %for.body344, %for.body276.lr.ph, %for.body276.lr.ph
30 %indvar = phi i64 [ %indvar.next, %for.body344 ], [ 0, %for.body276.lr.ph ]
30 %indvar = phi i64 [ %indvar.next, %for.body344 ], [ 0, %for.body276.lr.ph ], [ 0, %for.body276.lr.ph ]
3131 %indvars.iv552 = phi i64 [ %indvars.iv.next553, %for.body344 ], [ 0, %for.body276.lr.ph ], [ 0, %for.body276.lr.ph ]
3232 %indvars.iv.next553 = add nuw nsw i64 %indvars.iv552, 1
3333 %indvar.next = add i64 %indvar, 1
1414 to label %try_exit unwind label %try_catch
1515 try_catch: ; preds = %invoke_cont.0, %then
1616 %__tmp.0 = phi i32* [ null, %invoke_cont.0 ], [ null, %then ] ; [#uses=0]
17 %res = landingpad { i8* } personality i32 (...)* @__gxx_personality_v0
18 cleanup
1719 ret void
1820 try_exit: ; preds = %invoke_cont.0
1921 ret void
2022 }
2123
24 declare i32 @__gxx_personality_v0(...)
9898 %tmp10.1 = phi %0* [ %tmp10.0, %bb76 ], [ null, %bb ]
9999 %tmp83 = bitcast %0* %tmp10.1 to i8*
100100 %tmp84 = call i8* @objc_retain(i8* %tmp83) nounwind
101 %tmp88 = bitcast i8* %tmp87 to %0*
102101 call void @objc_release(i8* %tmp23) nounwind
103102 %tmp87 = call i8* @objc_autorelease(i8* %tmp84) nounwind
103 %tmp88 = bitcast i8* %tmp87 to %0*
104104 %tmp92 = bitcast %0* %tmp10.1 to i8*
105105 call void @objc_release(i8* %tmp92) nounwind
106106 ret %0* %tmp88
2121 invoke void @test2( )
2222 to label %N unwind label %U
2323 U:
24 %res = landingpad { i8* } personality i32 (...)* @__gxx_personality_v0
25 cleanup
2426 unreachable
2527 N:
2628 ret void
2729 }
30
31 declare i32 @__gxx_personality_v0(...)
2832
2933 define i32 @test3(i32 %v) {
3034 ; CHECK-LABEL: @test3(
2424 #include "llvm/IR/LLVMContext.h"
2525 #include "llvm/IR/LegacyPassManager.h"
2626 #include "llvm/IR/Module.h"
27 #include "llvm/IR/Verifier.h"
2728 #include "llvm/IRReader/IRReader.h"
2829 #include "llvm/MC/SubtargetFeature.h"
2930 #include "llvm/Pass.h"
224225 return 1;
225226 }
226227
228 // Verify module immediately to catch problems before doInitialization() is
229 // called on any passes.
230 if (!NoVerify && verifyModule(*M, &errs())) {
231 errs() << argv[0] << ": " << InputFilename
232 << ": error: does not verify\n";
233 return 1;
234 }
235
227236 // If we are supposed to override the target triple, do so now.
228237 if (!TargetTriple.empty())
229238 M->setTargetTriple(Triple::normalize(TargetTriple));
2424 #include "llvm/Bitcode/BitcodeWriterPass.h"
2525 #include "llvm/CodeGen/CommandFlags.h"
2626 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/DebugInfo.h"
2728 #include "llvm/IR/IRPrintingPasses.h"
2829 #include "llvm/IR/LLVMContext.h"
2930 #include "llvm/IR/LegacyPassNameParser.h"
344345 return 1;
345346 }
346347
348 // Strip debug info before running the verifier.
349 if (StripDebug)
350 StripDebugInfo(*M);
351
352 // Immediately run the verifier to catch any problems before starting up the
353 // pass pipelines. Otherwise we can crash on broken code during
354 // doInitialization().
355 if (!NoVerify && verifyModule(*M, &errs())) {
356 errs() << argv[0] << ": " << InputFilename << ": error: does not verify\n";
357 return 1;
358 }
359
347360 // If we are supposed to override the target triple, do so now.
348361 if (!TargetTriple.empty())
349362 M->setTargetTriple(Triple::normalize(TargetTriple));
447460 Passes.add(createBreakpointPrinter(Out->os()));
448461 NoOutput = true;
449462 }
450
451 // If the -strip-debug command line option was specified, add it.
452 if (StripDebug)
453 addPass(Passes, createStripSymbolsPass(true));
454463
455464 // Create a new optimization pass for each one specified on the command line
456465 for (unsigned i = 0; i < PassList.size(); ++i) {