1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -newgvn -enable-phi-of-ops=true -S < %s | FileCheck %s
3 ; RUN: opt -passes=newgvn -enable-phi-of-ops=true -S -o - %s | FileCheck %s
5 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7 ;; All the loads in this testcase are useless, but it requires understanding that repeated
8 ;; stores of the same value do not change the memory state to eliminate them.
10 define i32 @foo(i32*, i32) {
12 ; CHECK-NEXT: store i32 5, i32* [[TMP0:%.*]], align 4
13 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP1:%.*]], 0
14 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP5:%.*]]
15 ; CHECK: br label [[TMP5]]
16 ; CHECK: [[PHIOFOPS:%.*]] = phi i32 [ 10, [[TMP2:%.*]] ], [ 15, [[TMP4]] ]
17 ; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ 10, [[TMP4]] ], [ 5, [[TMP2]] ]
18 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP6:%.*]], label [[TMP7:%.*]]
19 ; CHECK: br label [[TMP7]]
20 ; CHECK: [[DOT1:%.*]] = phi i32 [ [[PHIOFOPS]], [[TMP6]] ], [ [[DOT0]], [[TMP5]] ]
21 ; CHECK-NEXT: ret i32 [[DOT1]]
23 store i32 5, i32* %0, align 4
24 %3 = icmp ne i32 %1, 0
25 br i1 %3, label %4, label %7
27 ; <label>:4: ; preds = %2
28 %5 = load i32, i32* %0, align 4
29 %6 = add nsw i32 5, %5
32 ; <label>:7: ; preds = %4, %2
33 %.0 = phi i32 [ %6, %4 ], [ 5, %2 ]
34 store i32 5, i32* %0, align 4
35 %8 = icmp ne i32 %1, 0
36 br i1 %8, label %9, label %12
38 ; <label>:9: ; preds = %7
39 %10 = load i32, i32* %0, align 4
40 %11 = add nsw i32 %.0, %10
43 ; <label>:12: ; preds = %9, %7
44 %.1 = phi i32 [ %11, %9 ], [ %.0, %7 ]
48 ;; This is similar to the above, but it is a conditional store of the same value
49 ;; which requires value numbering MemoryPhi properly to resolve.
50 define i32 @foo2(i32*, i32) {
52 ; CHECK-NEXT: store i32 5, i32* [[TMP0:%.*]], align 4
53 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP1:%.*]], 0
54 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP5:%.*]]
55 ; CHECK: br label [[TMP6:%.*]]
56 ; CHECK: br label [[TMP6]]
57 ; CHECK: [[PHIOFOPS:%.*]] = phi i32 [ 10, [[TMP5]] ], [ 15, [[TMP4]] ]
58 ; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ 10, [[TMP4]] ], [ 5, [[TMP5]] ]
59 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP7:%.*]], label [[TMP8:%.*]]
60 ; CHECK: br label [[TMP8]]
61 ; CHECK: [[DOT1:%.*]] = phi i32 [ [[PHIOFOPS]], [[TMP7]] ], [ [[DOT0]], [[TMP6]] ]
62 ; CHECK-NEXT: ret i32 [[DOT1]]
64 store i32 5, i32* %0, align 4
65 %3 = icmp ne i32 %1, 0
66 br i1 %3, label %4, label %7
68 ; <label>:4: ; preds = %2
69 %5 = load i32, i32* %0, align 4
70 %6 = add nsw i32 5, %5
73 ; <label>:7: ; preds = %2
74 store i32 5, i32* %0, align 4
77 ; <label>:8: ; preds = %7, %4
78 %.0 = phi i32 [ %6, %4 ], [ 5, %7 ]
79 %9 = icmp ne i32 %1, 0
80 br i1 %9, label %10, label %13
82 ; <label>:10: ; preds = %8
83 %11 = load i32, i32* %0, align 4
84 %12 = add nsw i32 %.0, %11
87 ; <label>:13: ; preds = %10, %8
88 %.1 = phi i32 [ %12, %10 ], [ %.0, %8 ]