1; RUN: opt -gvn %s -S | FileCheck %s
2; PR42605. Check phi-translate won't translate the value number of a call
3; to the value of another call with clobber in between.
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7@global = dso_local local_unnamed_addr global i32 0, align 4
8@.str = private unnamed_addr constant [8 x i8] c"%d, %d\0A\00", align 1
9
10; Function Attrs: nofree nounwind
11declare dso_local i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr
12
13; Function Attrs: noinline norecurse nounwind readonly uwtable
14define dso_local i32 @_Z3gooi(i32 %i) local_unnamed_addr #0 {
15entry:
16  %t0 = load i32, i32* @global, align 4, !tbaa !2
17  %add = add nsw i32 %t0, %i
18  ret i32 %add
19}
20
21; Function Attrs: nofree nounwind uwtable
22define dso_local void @noclobber() local_unnamed_addr {
23entry:
24  %call = tail call i32 @_Z3gooi(i32 2)
25  %add = add nsw i32 %call, 5
26  %cmp = icmp sgt i32 %add, 2
27  br i1 %cmp, label %if.then, label %if.end
28
29if.then:                                          ; preds = %entry
30  %call1 = tail call i32 @_Z3gooi(i32 3)
31  %add2 = add nsw i32 %call1, 5
32  br label %if.end
33
34; Check pre happens after phitranslate.
35; CHECK-LABEL: @noclobber
36; CHECK: %add4.pre-phi = phi i32 [ %add2, %if.then ], [ %add, %entry ]
37; CHECK: printf(i8* getelementptr inbounds {{.*}}, i32 %add4.pre-phi)
38
39if.end:                                           ; preds = %if.then, %entry
40  %i.0 = phi i32 [ 3, %if.then ], [ 2, %entry ]
41  %global2.0 = phi i32 [ %add2, %if.then ], [ %add, %entry ]
42  %call3 = tail call i32 @_Z3gooi(i32 %i.0)
43  %add4 = add nsw i32 %call3, 5
44  %call5 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %global2.0, i32 %add4)
45  ret void
46}
47
48; Function Attrs: nofree nounwind uwtable
49define dso_local void @hasclobber() local_unnamed_addr {
50entry:
51  %call = tail call i32 @_Z3gooi(i32 2)
52  %add = add nsw i32 %call, 5
53  %cmp = icmp sgt i32 %add, 2
54  br i1 %cmp, label %if.then, label %if.end
55
56if.then:                                          ; preds = %entry
57  %call1 = tail call i32 @_Z3gooi(i32 3)
58  %add2 = add nsw i32 %call1, 5
59  br label %if.end
60
61; Check no pre happens.
62; CHECK-LABEL: @hasclobber
63; CHECK: %call3 = tail call i32 @_Z3gooi(i32 %i.0)
64; CHECK-NEXT: %add4 = add nsw i32 %call3, 5
65; CHECK-NEXT: printf(i8* getelementptr inbounds ({{.*}}, i32 %global2.0, i32 %add4)
66
67if.end:                                           ; preds = %if.then, %entry
68  %i.0 = phi i32 [ 3, %if.then ], [ 2, %entry ]
69  %global2.0 = phi i32 [ %add2, %if.then ], [ %add, %entry ]
70  store i32 5, i32* @global, align 4, !tbaa !2
71  %call3 = tail call i32 @_Z3gooi(i32 %i.0)
72  %add4 = add nsw i32 %call3, 5
73  %call5 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %global2.0, i32 %add4)
74  ret void
75}
76
77attributes #0 = { noinline norecurse nounwind readonly uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
78
79!llvm.module.flags = !{!0}
80!llvm.ident = !{!1}
81
82!0 = !{i32 1, !"wchar_size", i32 4}
83!1 = !{!"clang version 10.0.0 (trunk 369798)"}
84!2 = !{!3, !3, i64 0}
85!3 = !{!"int", !4, i64 0}
86!4 = !{!"omnipotent char", !5, i64 0}
87!5 = !{!"Simple C++ TBAA"}
88