llvm.org GIT mirror llvm / 0d1abb3
[NewGVN] Stop assuming PHI args ordering when looking at phi-of-ops. It's not guaranteed. There's a bug open to sort them in predecessor order, but it won't happen anytime soon. In the meanwhile, passes will have to do an O(#preds) scan. Such is life. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316953 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 1 year, 11 months ago
2 changed file(s) with 71 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
27652765 Deps.insert(Op);
27662766 } else if (auto *ValuePHI = RealToTemp.lookup(Op)) {
27672767 if (getBlockForValue(ValuePHI) == PHIBlock)
2768 Op = ValuePHI->getIncomingValue(PredNum);
2768 Op = ValuePHI->getIncomingValueForBlock(PredBB);
27692769 }
27702770 // If we phi-translated the op, it must be safe.
27712771 SafeForPHIOfOps =
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -newgvn -S %s | FileCheck %s
2
3 @a = common global i32 0, align 4
4 @.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
5 define i32 @main() #0 {
6 ; CHECK-LABEL: @main(
7 ; CHECK-NEXT: entry:
8 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* @a, align 4
9 ; CHECK-NEXT: [[NEG:%.*]] = xor i32 [[TMP0]], -1
10 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP0]], -1
11 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
12 ; CHECK: if.then:
13 ; CHECK-NEXT: br label [[IF_END]]
14 ; CHECK: if.end:
15 ; CHECK-NEXT: [[PHIOFOPS:%.*]] = phi i32 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[NEG]], [[IF_THEN]] ]
16 ; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[TMP0]], [[IF_THEN]] ], [ [[NEG]], [[ENTRY]] ]
17 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[STOREMERGE]], [[PHIOFOPS]]
18 ; CHECK-NEXT: br i1 [[CMP2]], label [[IF_THEN3:%.*]], label [[IF_END6:%.*]]
19 ; CHECK: if.then3:
20 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[STOREMERGE]], -1
21 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[LOR_RHS:%.*]], label [[LOR_END:%.*]]
22 ; CHECK: lor.rhs:
23 ; CHECK-NEXT: [[TOBOOL5:%.*]] = icmp ne i32 [[TMP0]], 0
24 ; CHECK-NEXT: [[PHITMP:%.*]] = zext i1 [[TOBOOL5]] to i32
25 ; CHECK-NEXT: br label [[LOR_END]]
26 ; CHECK: lor.end:
27 ; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ 1, [[IF_THEN3]] ], [ [[PHITMP]], [[LOR_RHS]] ]
28 ; CHECK-NEXT: store i32 [[TMP1]], i32* @a, align 4
29 ; CHECK-NEXT: br label [[IF_END6]]
30 ; CHECK: if.end6:
31 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* @a, align 4
32 ; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 [[TMP2]])
33 ; CHECK-NEXT: ret i32 0
34 ;
35 entry:
36 %0 = load i32, i32* @a, align 4
37 %neg = xor i32 %0, -1
38 %cmp = icmp sgt i32 %0, -1
39 br i1 %cmp, label %if.then, label %if.end
40
41 if.then:
42 br label %if.end
43
44 if.end:
45 %storemerge = phi i32 [ %0, %if.then ], [ %neg, %entry ]
46 %neg1 = xor i32 %storemerge, -1
47 %cmp2 = icmp ult i32 %storemerge, %neg1
48 br i1 %cmp2, label %if.then3, label %if.end6
49
50 if.then3:
51 %tobool = icmp eq i32 %storemerge, -1
52 br i1 %tobool, label %lor.rhs, label %lor.end
53
54 lor.rhs:
55 %tobool5 = icmp ne i32 %0, 0
56 %phitmp = zext i1 %tobool5 to i32
57 br label %lor.end
58
59 lor.end:
60 %1 = phi i32 [ 1, %if.then3 ], [ %phitmp, %lor.rhs ]
61 store i32 %1, i32* @a, align 4
62 br label %if.end6
63
64 if.end6:
65 %2 = load i32, i32* @a, align 4
66 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %2) #3
67 ret i32 0
68 }
69 declare i32 @printf(i8*, ...) #2