xref: /llvm-project/llvm/test/Transforms/CodeGenPrepare/X86/fake-use-phi.ll (revision 3d08ade7bd32f0296e0ca3a13640cc95fa89229a)
1; RUN: opt < %s -passes='require<profile-summary>,function(codegenprepare)' -S -mtriple=x86_64 | FileCheck %s --implicit-check-not="llvm.fake.use"
2;
3; When performing return duplication to enable
4; tail call optimization we clone fake uses that exist in the to-be-eliminated
5; return block into the predecessor blocks. When doing this with fake uses
6; of PHI-nodes, they cannot be easily copied, but require the correct operand.
7; We are currently not able to do this correctly, so we suppress the cloning
8; of such fake uses at the moment.
9;
10; There should be no fake use of a call result in any of the resulting return
11; blocks.
12
13; Fake uses of `this` should be duplicated into both return blocks.
14; CHECK: if.then:
15; CHECK: @llvm.fake.use({{.*}}this
16; CHECK: if.else:
17; CHECK: @llvm.fake.use({{.*}}this
18
19; CHECK: declare void @llvm.fake.use
20
21source_filename = "test.ll"
22
23%class.a = type { i8 }
24
25declare i32 @foo(ptr nonnull dereferenceable(1)) local_unnamed_addr
26declare i32 @bar(ptr nonnull dereferenceable(1)) local_unnamed_addr
27
28define hidden void @func(ptr nonnull dereferenceable(1) %this) local_unnamed_addr align 2 optdebug {
29entry:
30  %b = getelementptr inbounds %class.a, ptr %this, i64 0, i32 0
31  %0 = load i8, i8* %b, align 1
32  %tobool.not = icmp eq i8 %0, 0
33  br i1 %tobool.not, label %if.else, label %if.then
34
35if.then:                                          ; preds = %entry
36  %call = tail call i32 @foo(ptr nonnull dereferenceable(1) %this)
37  %call2 = tail call i32 @bar(ptr nonnull dereferenceable(1) %this)
38  br label %if.end
39
40if.else:                                          ; preds = %entry
41  %call4 = tail call i32 @bar(ptr nonnull dereferenceable(1) %this)
42  %call5 = tail call i32 @foo(ptr nonnull dereferenceable(1) %this)
43  br label %if.end
44
45if.end:                                           ; preds = %if.else, %if.then
46  %call4.sink = phi i32 [ %call4, %if.else ], [ %call, %if.then ]
47  notail call void (...) @llvm.fake.use(i32 %call4.sink)
48  notail call void (...) @llvm.fake.use(ptr nonnull %this)
49  ret void
50}
51