Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 3bd51b8

Browse files
committed
Fix switch_to_lookup_table.ll test from r163302.
The lookup tables did not get built in a deterministic order. This makes them get built in the order that the corresponding phi nodes were found. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163305 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ba8562a commit 3bd51b8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,13 +3190,14 @@ static bool SwitchToLookupTable(SwitchInst *SI,
31903190
SmallDenseMap<PHINode*, Constant*> SingleResults;
31913191

31923192
Module &Mod = *CommonDest->getParent()->getParent();
3193-
for (SmallDenseMap<PHINode*, ResultListTy>::iterator I = ResultLists.begin(),
3194-
E = ResultLists.end(); I != E; ++I) {
3195-
PHINode *PHI = I->first;
3193+
for (SmallVector<PHINode*, 4>::iterator I = PHIs.begin(), E = PHIs.end();
3194+
I != E; ++I) {
3195+
PHINode *PHI = *I;
31963196

31973197
Constant *SingleResult = NULL;
3198-
LookupTables[PHI] = BuildLookupTable(Mod, TableSize, MinCaseVal, I->second,
3199-
DefaultResults[PHI], &SingleResult);
3198+
LookupTables[PHI] = BuildLookupTable(Mod, TableSize, MinCaseVal,
3199+
ResultLists[PHI], DefaultResults[PHI],
3200+
&SingleResult);
32003201
SingleResults[PHI] = SingleResult;
32013202
}
32023203

test/Transforms/SimplifyCFG/switch_to_lookup_table.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ target triple = "x86_64-unknown-linux-gnu"
66
; The table for @f
77
; CHECK: @switch.table = private unnamed_addr constant [7 x i32] [i32 55, i32 123, i32 0, i32 -1, i32 27, i32 62, i32 1]
88

9-
; The float table for @h
10-
; CHECK: @switch.table1 = private unnamed_addr constant [4 x float] [float 0x40091EB860000000, float 0x3FF3BE76C0000000, float 0x4012449BA0000000, float 0x4001AE1480000000]
11-
129
; The int table for @h
13-
; CHECK: @switch.table2 = private unnamed_addr constant [4 x i8] c"*\09X\05"
10+
; CHECK: @switch.table1 = private unnamed_addr constant [4 x i8] c"*\09X\05"
11+
12+
; The float table for @h
13+
; CHECK: @switch.table2 = private unnamed_addr constant [4 x float] [float 0x40091EB860000000, float 0x3FF3BE76C0000000, float 0x4012449BA0000000, float 0x4001AE1480000000]
1414

1515
; The table for @foostring
1616
; CHECK: @switch.table3 = private unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str3, i64 0, i64 0)]
@@ -85,9 +85,9 @@ sw.epilog:
8585
; CHECK-NEXT: %0 = icmp ult i32 %switch.tableidx, 4
8686
; CHECK-NEXT: br i1 %0, label %switch.lookup, label %sw.epilog
8787
; CHECK: switch.lookup:
88-
; CHECK-NEXT: %switch.gep = getelementptr inbounds [4 x i8]* @switch.table2, i32 0, i32 %switch.tableidx
88+
; CHECK-NEXT: %switch.gep = getelementptr inbounds [4 x i8]* @switch.table1, i32 0, i32 %switch.tableidx
8989
; CHECK-NEXT: %switch.load = load i8* %switch.gep
90-
; CHECK-NEXT: %switch.gep1 = getelementptr inbounds [4 x float]* @switch.table1, i32 0, i32 %switch.tableidx
90+
; CHECK-NEXT: %switch.gep1 = getelementptr inbounds [4 x float]* @switch.table2, i32 0, i32 %switch.tableidx
9191
; CHECK-NEXT: %switch.load2 = load float* %switch.gep1
9292
; CHECK-NEXT: br label %sw.epilog
9393
; CHECK: sw.epilog:

0 commit comments

Comments
 (0)