aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
blob: e1d99fd932fb7ae04af7e121e37a1a96563f22dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -S -mtriple=x86_64-linux < %s | FileCheck %s

define i32 @test1(ptr %d) nounwind {
; CHECK-LABEL: @test1(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[L:%.*]] = load i8, ptr [[D:%.*]], align 1
; CHECK-NEXT:    [[TMP0:%.*]] = icmp eq i8 [[L]], 0
; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[TMP0]] to i32
; CHECK-NEXT:    ret i32 [[CONV]]
;
entry:
  %l = load i8, ptr %d
  %cmp = icmp eq i8 %l, 0
  br i1 %cmp, label %exit, label %if.end

if.end:
  %gep = getelementptr i8, ptr %d, i32 42
  %call = call i64 @foo(ptr %gep) nounwind readonly willreturn
  %cmp2 = icmp ne i64 %call, 0
  call void @llvm.assume(i1 %cmp2)
  br label %exit

exit:
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

define i32 @test2(i32 %N) nounwind {
; CHECK-LABEL: @test2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[HEADER:%.*]]
; CHECK:       header:
; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[HEADER]] ]
; CHECK-NEXT:    [[IV_INC]] = add i32 [[IV]], 1
; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[IV]], [[N:%.*]]
; CHECK-NEXT:    br i1 [[CMP]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK:       exit:
; CHECK-NEXT:    ret i32 [[IV]]
;
entry:
  br label %header

header:
  %iv = phi i32 [0, %entry], [%iv.inc, %header]
  %iv2 = phi i32 [0, %entry], [%iv2.inc, %header]
  %iv.inc = add i32 %iv, 1
  %iv2.inc = add i32 %iv2, 1
  %cmp = icmp eq i32 %iv, %N
  %cmp2 = icmp sle i32 %iv2, %N
  call void @llvm.assume(i1 %cmp2)
  br i1 %cmp, label %exit, label %header

exit:
  ret i32 %iv
}

define i32 @test3(i32 %N) nounwind {
; CHECK-LABEL: @test3(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[HEADER:%.*]]
; CHECK:       header:
; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[HEADER]] ]
; CHECK-NEXT:    [[IV_INC]] = add i32 [[IV]], 1
; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[IV]], [[N:%.*]]
; CHECK-NEXT:    br i1 [[CMP]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK:       exit:
; CHECK-NEXT:    ret i32 [[IV]]
;
entry:
  br label %header

header:
  %iv = phi i32 [0, %entry], [%iv.inc, %header]
  %iv2 = phi i32 [0, %entry], [%iv2.inc, %header]
  %iv.inc = add i32 %iv, 1
  %iv2.inc = add i32 %iv2, 1
  %cmp = icmp eq i32 %iv, %N
  %cmp2 = icmp sle i32 %iv2.inc, %N
  call void @llvm.assume(i1 %cmp2)
  br i1 %cmp, label %exit, label %header

exit:
  ret i32 %iv
}

; Two assumes case.
define i32 @test4(i32 %N) nounwind {
; CHECK-LABEL: @test4(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[HEADER:%.*]]
; CHECK:       header:
; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[HEADER]] ]
; CHECK-NEXT:    [[IV_INC]] = add i32 [[IV]], 1
; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[IV]], [[N:%.*]]
; CHECK-NEXT:    br i1 [[CMP]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK:       exit:
; CHECK-NEXT:    ret i32 [[IV]]
;
entry:
  br label %header

header:
  %iv = phi i32 [0, %entry], [%iv.inc, %header]
  %iv2 = phi i32 [0, %entry], [%iv2.inc, %header]
  %iv.inc = add i32 %iv, 1
  %iv2.inc = add i32 %iv2, 1
  %cmp = icmp eq i32 %iv, %N
  %cmp2 = icmp sle i32 %iv2.inc, %N
  call void @llvm.assume(i1 %cmp2)
  %cmp3 = icmp sge i32 %iv2.inc, 0
  call void @llvm.assume(i1 %cmp3)
  br i1 %cmp, label %exit, label %header

exit:
  ret i32 %iv
}

; phi is used in assume and in compare.
define i32 @test5(i32 %N, i32 %M) nounwind {
; CHECK-LABEL: @test5(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[HEADER:%.*]]
; CHECK:       header:
; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[HEADER]] ]
; CHECK-NEXT:    [[IV2:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[IV2_INC:%.*]], [[HEADER]] ]
; CHECK-NEXT:    [[IV_INC]] = add i32 [[IV]], 1
; CHECK-NEXT:    [[IV2_INC]] = add i32 [[IV2]], 1
; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[IV]], [[N:%.*]]
; CHECK-NEXT:    [[CMP3:%.*]] = icmp sge i32 [[IV2_INC]], [[M:%.*]]
; CHECK-NEXT:    [[CMP4:%.*]] = and i1 [[CMP]], [[CMP3]]
; CHECK-NEXT:    br i1 [[CMP4]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK:       exit:
; CHECK-NEXT:    ret i32 [[IV]]
;
entry:
  br label %header

header:
  %iv = phi i32 [0, %entry], [%iv.inc, %header]
  %iv2 = phi i32 [0, %entry], [%iv2.inc, %header]
  %iv.inc = add i32 %iv, 1
  %iv2.inc = add i32 %iv2, 1
  %cmp = icmp eq i32 %iv, %N
  %cmp2 = icmp sle i32 %iv2.inc, %N
  call void @llvm.assume(i1 %cmp2)
  %cmp3 = icmp sge i32 %iv2.inc, %M
  %cmp4 = and i1 %cmp, %cmp3
  br i1 %cmp4, label %exit, label %header

exit:
  ret i32 %iv
}

declare i64 @foo(ptr) nounwind readonly willreturn
declare void @llvm.assume(i1 noundef) nounwind willreturn