xref: /llvm-project/llvm/test/Transforms/NewGVN/pr32952.ll (revision 229640343e400394b315c6798c7c19e8a9bd188c)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2; PR32952: Don't erroneously consider congruent two phi nodes which
3; have the same arguments but different incoming edges.
4; RUN: opt -passes=newgvn -S %s | FileCheck %s
5
6@a = common global i16 0, align 2
7@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
8
9define i32 @tinkywinky() {
10; CHECK-LABEL: define i32 @tinkywinky() {
11; CHECK-NEXT:  entry:
12; CHECK-NEXT:    [[TMP0:%.*]] = load i16, ptr @a, align 2
13; CHECK-NEXT:    [[CONV:%.*]] = sext i16 [[TMP0]] to i32
14; CHECK-NEXT:    [[NEG:%.*]] = xor i32 [[CONV]], -1
15; CHECK-NEXT:    [[CONV1:%.*]] = trunc i32 [[NEG]] to i16
16; CHECK-NEXT:    [[CONV3:%.*]] = zext i16 [[CONV1]] to i32
17; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[CONV]], [[CONV3]]
18; CHECK-NEXT:    br i1 [[CMP]], label [[TINKY:%.*]], label [[WINKY:%.*]]
19; CHECK:       tinky:
20; CHECK-NEXT:    store i16 2, ptr @a, align 2
21; CHECK-NEXT:    br label [[PATATINO:%.*]]
22; CHECK:       winky:
23; CHECK-NEXT:    br label [[PATATINO]]
24; CHECK:       patatino:
25; CHECK-NEXT:    [[MEH:%.*]] = phi i16 [ [[TMP0]], [[WINKY]] ], [ [[CONV1]], [[TINKY]] ]
26; CHECK-NEXT:    [[BANANA:%.*]] = phi i16 [ [[TMP0]], [[TINKY]] ], [ [[CONV1]], [[WINKY]] ]
27; CHECK-NEXT:    br label [[END:%.*]]
28; CHECK:       end:
29; CHECK-NEXT:    [[PROMOTED:%.*]] = zext i16 [[BANANA]] to i32
30; CHECK-NEXT:    [[OTHER:%.*]] = zext i16 [[MEH]] to i32
31; CHECK-NEXT:    [[FIRST:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str, i32 [[PROMOTED]])
32; CHECK-NEXT:    [[SECOND:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str, i32 [[OTHER]])
33; CHECK-NEXT:    ret i32 0
34;
35entry:
36  %0 = load i16, ptr @a, align 2
37  %conv = sext i16 %0 to i32
38  %neg = xor i32 %conv, -1
39  %conv1 = trunc i32 %neg to i16
40  %conv3 = zext i16 %conv1 to i32
41  %cmp = icmp slt i32 %conv, %conv3
42  br i1 %cmp, label %tinky, label %winky
43
44tinky:
45  store i16 2, ptr @a, align 2
46  br label %patatino
47
48winky:
49  br label %patatino
50
51patatino:
52  %meh = phi i16 [ %0, %winky ], [ %conv1, %tinky ]
53  %banana = phi i16 [ %0, %tinky ], [ %conv1, %winky ]
54  br label %end
55
56end:
57  %promoted = zext i16 %banana to i32
58  %other = zext i16 %meh to i32
59  %first = tail call i32 (ptr, ...) @printf(ptr @.str, i32 %promoted)
60  %second = tail call i32 (ptr, ...) @printf(ptr @.str, i32 %other)
61  ret i32 0
62}
63
64declare i32 @printf(ptr, ...)
65