Skip to content

Commit a6d30c8

Browse files
committed
add a few tests
1 parent 1c8845a commit a6d30c8

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; RUN: opt -passes="default<O3>" -enable-merge-functions -S < %s | FileCheck %s
2+
3+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-apple-macosx12.0.0"
5+
6+
; Function Attrs: noinline nounwind optsize ssp uwtable
7+
define i32 @f(i32 noundef %x) #0 {
8+
; CHECK-LABEL: @f(
9+
entry:
10+
%x.addr = alloca i32, align 4
11+
store i32 %x, ptr %x.addr, align 4, !tbaa !5
12+
%0 = load i32, ptr %x.addr, align 4, !tbaa !5
13+
switch i32 %0, label %sw.default [
14+
i32 0, label %sw.bb
15+
i32 2, label %sw.bb
16+
i32 4, label %sw.bb
17+
i32 6, label %sw.bb
18+
i32 7, label %sw.bb
19+
]
20+
21+
sw.bb: ; preds = %entry, %entry, %entry, %entry, %entry
22+
store i32 1, ptr %x.addr, align 4, !tbaa !5
23+
br label %sw.epilog
24+
25+
sw.default: ; preds = %entry
26+
store i32 0, ptr %x.addr, align 4, !tbaa !5
27+
br label %sw.epilog
28+
29+
sw.epilog: ; preds = %sw.default, %sw.bb
30+
%1 = load i32, ptr %x.addr, align 4, !tbaa !5
31+
ret i32 %1
32+
}
33+
34+
; Function Attrs: noinline nounwind optsize ssp uwtable
35+
define i32 @g(i32 noundef %x) #0 {
36+
; CHECK-LABEL: @g(
37+
; CHECK-NEXT: [[TMP2:%.*]] = tail call range(i32 0, 2) i32 @f(i32 noundef [[TMP0:%.*]]) #[[ATTR0:[0-9]+]]
38+
; CHECK-NEXT: ret i32 [[TMP2]]
39+
entry:
40+
%x.addr = alloca i32, align 4
41+
store i32 %x, ptr %x.addr, align 4, !tbaa !5
42+
%0 = load i32, ptr %x.addr, align 4, !tbaa !5
43+
switch i32 %0, label %sw.default [
44+
i32 0, label %sw.bb
45+
i32 2, label %sw.bb
46+
i32 4, label %sw.bb
47+
i32 6, label %sw.bb
48+
i32 7, label %sw.bb
49+
]
50+
51+
sw.bb: ; preds = %entry, %entry, %entry, %entry, %entry
52+
store i32 1, ptr %x.addr, align 4, !tbaa !5
53+
br label %sw.epilog
54+
55+
sw.default: ; preds = %entry
56+
store i32 0, ptr %x.addr, align 4, !tbaa !5
57+
br label %sw.epilog
58+
59+
sw.epilog: ; preds = %sw.default, %sw.bb
60+
%1 = load i32, ptr %x.addr, align 4, !tbaa !5
61+
ret i32 %1
62+
}
63+
64+
!5 = !{!6, !6, i64 0}
65+
!6 = !{!"int", !7, i64 0}
66+
!7 = !{!"omnipotent char", !8, i64 0}
67+
!8 = !{!"Simple C/C++ TBAA"}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: opt -passes="default<O3>" -enable-merge-functions -S < %s | FileCheck %s
2+
3+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-apple-macosx12.0.0"
5+
6+
@switch.table.f = private unnamed_addr constant [8 x i32] [i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 1], align 4
7+
@switch.table.g = private unnamed_addr constant [8 x i32] [i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 1], align 4
8+
9+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind optsize ssp willreturn memory(none) uwtable
10+
define range(i32 0, 2) i32 @f(i32 noundef %x) local_unnamed_addr #0 {
11+
; CHECK-LABEL: @f(
12+
entry:
13+
%0 = icmp ult i32 %x, 8
14+
br i1 %0, label %switch.lookup, label %sw.epilog
15+
16+
switch.lookup: ; preds = %entry
17+
%1 = zext nneg i32 %x to i64
18+
%switch.gep = getelementptr inbounds [8 x i32], ptr @switch.table.f, i64 0, i64 %1
19+
%switch.load = load i32, ptr %switch.gep, align 4
20+
br label %sw.epilog
21+
22+
sw.epilog: ; preds = %entry, %switch.lookup
23+
%x.addr.0 = phi i32 [ %switch.load, %switch.lookup ], [ 0, %entry ]
24+
ret i32 %x.addr.0
25+
}
26+
27+
; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind optsize ssp willreturn memory(none) uwtable
28+
define range(i32 0, 2) i32 @g(i32 noundef %x) local_unnamed_addr #0 {
29+
; CHECK-LABEL: @g(
30+
; CHECK-NEXT: [[TMP2:%.*]] = tail call range(i32 0, 2) i32 @f(i32 noundef [[TMP0:%.*]]) #[[ATTR0:[0-9]+]]
31+
; CHECK-NEXT: ret i32 [[TMP2]]
32+
entry:
33+
%0 = icmp ult i32 %x, 8
34+
br i1 %0, label %switch.lookup, label %sw.epilog
35+
36+
switch.lookup: ; preds = %entry
37+
%1 = zext nneg i32 %x to i64
38+
%switch.gep = getelementptr inbounds [8 x i32], ptr @switch.table.g, i64 0, i64 %1
39+
%switch.load = load i32, ptr %switch.gep, align 4
40+
br label %sw.epilog
41+
42+
sw.epilog: ; preds = %entry, %switch.lookup
43+
%x.addr.0 = phi i32 [ %switch.load, %switch.lookup ], [ 0, %entry ]
44+
ret i32 %x.addr.0
45+
}
46+
47+
attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind optsize ssp willreturn memory(none) uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cmov,+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }

0 commit comments

Comments
 (0)