2009-12-22 14:04:26 +08:00
|
|
|
; Test CFG simplify removal of branch instructions.
|
2002-05-06 10:37:38 +08:00
|
|
|
;
|
2009-12-22 14:04:26 +08:00
|
|
|
; RUN: opt < %s -simplifycfg -S | FileCheck %s
|
2015-02-01 19:34:21 +08:00
|
|
|
; RUN: opt < %s -passes=simplify-cfg -S | FileCheck %s
|
2002-05-06 10:37:38 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define void @test1() {
|
2010-12-13 13:10:30 +08:00
|
|
|
br label %1
|
2008-03-18 11:45:45 +08:00
|
|
|
ret void
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2009-12-22 14:04:26 +08:00
|
|
|
; CHECK-NEXT: ret void
|
2002-05-06 10:37:38 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define void @test2() {
|
|
|
|
ret void
|
|
|
|
ret void
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2009-12-22 14:04:26 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
2002-05-06 10:37:38 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define void @test3(i1 %T) {
|
2010-12-13 13:10:30 +08:00
|
|
|
br i1 %T, label %1, label %1
|
2008-03-18 11:45:45 +08:00
|
|
|
ret void
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2009-12-22 14:04:26 +08:00
|
|
|
; CHECK-NEXT: ret void
|
2002-05-06 10:37:38 +08:00
|
|
|
}
|
|
|
|
|
2016-05-06 22:25:14 +08:00
|
|
|
; Folding branch to a common destination.
|
|
|
|
; CHECK-LABEL: @test4_fold
|
|
|
|
; CHECK: %cmp1 = icmp eq i32 %a, %b
|
|
|
|
; CHECK: %cmp2 = icmp ugt i32 %a, 0
|
|
|
|
; CHECK: %or.cond = and i1 %cmp1, %cmp2
|
|
|
|
; CHECK: br i1 %or.cond, label %else, label %untaken
|
|
|
|
; CHECK-NOT: taken:
|
|
|
|
; CHECK: ret void
|
|
|
|
define void @test4_fold(i32 %a, i32 %b) {
|
|
|
|
%cmp1 = icmp eq i32 %a, %b
|
|
|
|
br i1 %cmp1, label %taken, label %untaken
|
|
|
|
|
|
|
|
taken:
|
|
|
|
%cmp2 = icmp ugt i32 %a, 0
|
|
|
|
br i1 %cmp2, label %else, label %untaken
|
|
|
|
|
|
|
|
else:
|
|
|
|
call void @foo()
|
|
|
|
ret void
|
|
|
|
|
|
|
|
untaken:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Prefer a simplification based on a dominating condition rather than folding a
|
|
|
|
; branch to a common destination.
|
|
|
|
; CHECK-LABEL: @test4
|
|
|
|
; CHECK-NOT: br
|
|
|
|
; CHECK-NOT: br
|
|
|
|
; CHECK-NOT: call
|
|
|
|
; CHECK: ret void
|
|
|
|
define void @test4_no_fold(i32 %a, i32 %b) {
|
|
|
|
%cmp1 = icmp eq i32 %a, %b
|
|
|
|
br i1 %cmp1, label %taken, label %untaken
|
|
|
|
|
|
|
|
taken:
|
|
|
|
%cmp2 = icmp ugt i32 %a, %b
|
|
|
|
br i1 %cmp2, label %else, label %untaken
|
|
|
|
|
|
|
|
else:
|
|
|
|
call void @foo()
|
|
|
|
ret void
|
|
|
|
|
|
|
|
untaken:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void @foo()
|
2002-05-06 10:37:38 +08:00
|
|
|
|
2009-12-22 14:07:30 +08:00
|
|
|
; PR5795
|
|
|
|
define void @test5(i32 %A) {
|
|
|
|
switch i32 %A, label %return [
|
2010-12-13 13:10:30 +08:00
|
|
|
i32 2, label %1
|
|
|
|
i32 10, label %2
|
2009-12-22 14:07:30 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
ret void
|
|
|
|
|
|
|
|
ret void
|
|
|
|
|
|
|
|
return: ; preds = %entry
|
|
|
|
ret void
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
2009-12-22 14:07:30 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
}
|
2014-01-29 00:56:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
; PR14893
|
|
|
|
define i8 @test6f() {
|
|
|
|
; CHECK-LABEL: @test6f
|
|
|
|
; CHECK: alloca i8, align 1
|
|
|
|
; CHECK-NEXT: call i8 @test6g
|
|
|
|
; CHECK-NEXT: icmp eq i8 %tmp, 0
|
2015-08-21 02:24:02 +08:00
|
|
|
; CHECK-NEXT: load i8, i8* %r, align 1, !dbg !{{[0-9]+$}}
|
2014-01-29 00:56:46 +08:00
|
|
|
|
|
|
|
bb0:
|
|
|
|
%r = alloca i8, align 1
|
|
|
|
%tmp = call i8 @test6g(i8* %r)
|
|
|
|
%tmp1 = icmp eq i8 %tmp, 0
|
|
|
|
br i1 %tmp1, label %bb2, label %bb1
|
|
|
|
bb1:
|
[Verifier] Add verification for TBAA metadata
Summary:
This change adds some verification in the IR verifier around struct path
TBAA metadata.
Other than some basic sanity checks (e.g. we get constant integers where
we expect constant integers), this checks:
- That by the time an struct access tuple `(base-type, offset)` is
"reduced" to a scalar base type, the offset is `0`. For instance, in
C++ you can't start from, say `("struct-a", 16)`, and end up with
`("int", 4)` -- by the time the base type is `"int"`, the offset
better be zero. In particular, a variant of this invariant is needed
for `llvm::getMostGenericTBAA` to be correct.
- That there are no cycles in a struct path.
- That struct type nodes have their offsets listed in an ascending
order.
- That when generating the struct access path, you eventually reach the
access type listed in the tbaa tag node.
Reviewers: dexonsmith, chandlerc, reames, mehdi_amini, manmanren
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D26438
llvm-svn: 289402
2016-12-12 04:07:15 +08:00
|
|
|
%tmp3 = load i8, i8* %r, align 1, !range !2, !tbaa !10, !dbg !5
|
2014-01-29 00:56:46 +08:00
|
|
|
%tmp4 = icmp eq i8 %tmp3, 1
|
|
|
|
br i1 %tmp4, label %bb2, label %bb3
|
|
|
|
bb2:
|
|
|
|
br label %bb3
|
|
|
|
bb3:
|
|
|
|
%tmp6 = phi i8 [ 0, %bb2 ], [ 1, %bb1 ]
|
|
|
|
ret i8 %tmp6
|
|
|
|
}
|
|
|
|
declare i8 @test6g(i8*)
|
|
|
|
|
2015-08-21 02:24:02 +08:00
|
|
|
!llvm.dbg.cu = !{!3}
|
|
|
|
!llvm.module.flags = !{!8, !9}
|
|
|
|
|
[Verifier] Add verification for TBAA metadata
Summary:
This change adds some verification in the IR verifier around struct path
TBAA metadata.
Other than some basic sanity checks (e.g. we get constant integers where
we expect constant integers), this checks:
- That by the time an struct access tuple `(base-type, offset)` is
"reduced" to a scalar base type, the offset is `0`. For instance, in
C++ you can't start from, say `("struct-a", 16)`, and end up with
`("int", 4)` -- by the time the base type is `"int"`, the offset
better be zero. In particular, a variant of this invariant is needed
for `llvm::getMostGenericTBAA` to be correct.
- That there are no cycles in a struct path.
- That struct type nodes have their offsets listed in an ascending
order.
- That when generating the struct access path, you eventually reach the
access type listed in the tbaa tag node.
Reviewers: dexonsmith, chandlerc, reames, mehdi_amini, manmanren
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D26438
llvm-svn: 289402
2016-12-12 04:07:15 +08:00
|
|
|
!0 = !{!10, !10, i64 0}
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
|
|
|
!1 = !{!"foo"}
|
|
|
|
!2 = !{i8 0, i8 2}
|
2016-04-15 23:57:41 +08:00
|
|
|
!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !7, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !4)
|
2015-08-21 02:24:02 +08:00
|
|
|
!4 = !{}
|
|
|
|
!5 = !DILocation(line: 23, scope: !6)
|
2016-04-15 23:57:41 +08:00
|
|
|
!6 = distinct !DISubprogram(name: "foo", scope: !3, file: !7, line: 1, type: !DISubroutineType(types: !4), isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, variables: !4)
|
2015-08-21 02:24:02 +08:00
|
|
|
!7 = !DIFile(filename: "foo.c", directory: "/")
|
|
|
|
!8 = !{i32 2, !"Dwarf Version", i32 2}
|
|
|
|
!9 = !{i32 2, !"Debug Info Version", i32 3}
|
[Verifier] Add verification for TBAA metadata
Summary:
This change adds some verification in the IR verifier around struct path
TBAA metadata.
Other than some basic sanity checks (e.g. we get constant integers where
we expect constant integers), this checks:
- That by the time an struct access tuple `(base-type, offset)` is
"reduced" to a scalar base type, the offset is `0`. For instance, in
C++ you can't start from, say `("struct-a", 16)`, and end up with
`("int", 4)` -- by the time the base type is `"int"`, the offset
better be zero. In particular, a variant of this invariant is needed
for `llvm::getMostGenericTBAA` to be correct.
- That there are no cycles in a struct path.
- That struct type nodes have their offsets listed in an ascending
order.
- That when generating the struct access path, you eventually reach the
access type listed in the tbaa tag node.
Reviewers: dexonsmith, chandlerc, reames, mehdi_amini, manmanren
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D26438
llvm-svn: 289402
2016-12-12 04:07:15 +08:00
|
|
|
!10 = !{!"scalar type", !1}
|