Don't build switch tables for dllimport and TLS variables in GEPs
authorHans Wennborg <hans@hanshq.net>
Thu, 26 Jun 2014 00:30:52 +0000 (00:30 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 26 Jun 2014 00:30:52 +0000 (00:30 +0000)
This is a follow-up to r211331, which failed to notice that we were
returning early from ValidLookupTableConstant for GEPs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211753 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll

index ff2f2a0362254146dfa4db781f2a9d5ccfe7dea5..b1f9bff5377fff291e2fb41cfc466714def99698 100644 (file)
@@ -3311,13 +3311,14 @@ static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
 /// ValidLookupTableConstant - Return true if the backend will be able to handle
 /// initializing an array of constants like C.
 static bool ValidLookupTableConstant(Constant *C) {
 /// ValidLookupTableConstant - Return true if the backend will be able to handle
 /// initializing an array of constants like C.
 static bool ValidLookupTableConstant(Constant *C) {
-  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
-    return CE->isGEPWithNoNotionalOverIndexing();
   if (C->isThreadDependent())
     return false;
   if (C->isDLLImportDependent())
     return false;
 
   if (C->isThreadDependent())
     return false;
   if (C->isDLLImportDependent())
     return false;
 
+  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
+    return CE->isGEPWithNoNotionalOverIndexing();
+
   return isa<ConstantFP>(C) ||
       isa<ConstantInt>(C) ||
       isa<ConstantPointerNull>(C) ||
   return isa<ConstantFP>(C) ||
       isa<ConstantInt>(C) ||
       isa<ConstantPointerNull>(C) ||
index ee63d2c0c0f61633a2f6e09982c1f49084c7816f..51ced4099ac9648e620bc414d0b9018568a3023e 100644 (file)
@@ -946,10 +946,10 @@ return:
 }
 
 ; Don't build tables for switches with dllimport variables.
 }
 
 ; Don't build tables for switches with dllimport variables.
-@dllimport_a = external dllimport global i32
-@dllimport_b = external dllimport global i32
-@dllimport_c = external dllimport global i32
-@dllimport_d = external dllimport global i32
+@dllimport_a = external dllimport global [3x i32]
+@dllimport_b = external dllimport global [3x i32]
+@dllimport_c = external dllimport global [3x i32]
+@dllimport_d = external dllimport global [3x i32]
 define i32* @dllimport(i32 %x) {
 entry:
   switch i32 %x, label %sw.default [
 define i32* @dllimport(i32 %x) {
 entry:
   switch i32 %x, label %sw.default [
@@ -964,7 +964,10 @@ sw.bb2:
 sw.default:
   br label %return
 return:
 sw.default:
   br label %return
 return:
-  %retval.0 = phi i32* [ @dllimport_d, %sw.default ], [ @dllimport_c, %sw.bb2 ], [ @dllimport_b, %sw.bb1 ], [ @dllimport_a, %entry ]
+  %retval.0 = phi i32* [ getelementptr inbounds ([3 x i32]* @dllimport_d, i32 0, i32 0), %sw.default ],
+                       [ getelementptr inbounds ([3 x i32]* @dllimport_c, i32 0, i32 0), %sw.bb2 ],
+                       [ getelementptr inbounds ([3 x i32]* @dllimport_b, i32 0, i32 0), %sw.bb1 ],
+                       [ getelementptr inbounds ([3 x i32]* @dllimport_a, i32 0, i32 0), %entry ]
   ret i32* %retval.0
 ; CHECK-LABEL: @dllimport(
 ; CHECK: switch i32
   ret i32* %retval.0
 ; CHECK-LABEL: @dllimport(
 ; CHECK: switch i32