[llvm] r211753 - Don't build switch tables for dllimport and TLS variables in GEPs

Hans Wennborg hans at hanshq.net
Wed Jun 25 17:30:52 PDT 2014


Author: hans
Date: Wed Jun 25 19:30:52 2014
New Revision: 211753

URL: http://llvm.org/viewvc/llvm-project?rev=211753&view=rev
Log:
Don't build switch tables for dllimport and TLS variables in GEPs

This is a follow-up to r211331, which failed to notice that we were
returning early from ValidLookupTableConstant for GEPs.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=211753&r1=211752&r2=211753&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Wed Jun 25 19:30:52 2014
@@ -3311,13 +3311,14 @@ static bool ForwardSwitchConditionToPHI(
 /// 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 (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
+    return CE->isGEPWithNoNotionalOverIndexing();
+
   return isa<ConstantFP>(C) ||
       isa<ConstantInt>(C) ||
       isa<ConstantPointerNull>(C) ||

Modified: llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll?rev=211753&r1=211752&r2=211753&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll Wed Jun 25 19:30:52 2014
@@ -946,10 +946,10 @@ return:
 }
 
 ; Don't build tables for switches with dllimport variables.
- at dllimport_a = external dllimport global i32
- at dllimport_b = external dllimport global i32
- at dllimport_c = external dllimport global i32
- at dllimport_d = external dllimport global i32
+ at dllimport_a = external dllimport global [3x i32]
+ at dllimport_b = external dllimport global [3x i32]
+ at dllimport_c = external dllimport global [3x i32]
+ at dllimport_d = external dllimport global [3x i32]
 define i32* @dllimport(i32 %x) {
 entry:
   switch i32 %x, label %sw.default [
@@ -964,7 +964,10 @@ sw.bb2:
 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





More information about the llvm-commits mailing list