[PATCH] D25550: [SimplifyCFG] Don't lower complex ConstantExprs to lookup tables

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 01:42:36 PDT 2016


olista01 updated this revision to Diff 74627.
olista01 added a comment.

Add a triple to the test, and move it to the ARM directory. Previously, the transformation was never done because a TTI check for legal types fails with the default implementation.


Repository:
  rL LLVM

https://reviews.llvm.org/D25550

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll


Index: test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll
===================================================================
--- /dev/null
+++ test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll
@@ -0,0 +1,40 @@
+; RUN: opt -S -simplifycfg < %s | FileCheck %s --check-prefix=CHECK
+
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "armv7a--none-eabi"
+
+; One of the phi node's values is too complex to be represented by a global
+; variable, so we can't convert to a lookup table.
+
+; CHECK-NOT: @switch.table
+; CHECK-NOT: load
+
+ at g1 = external global i32, align 4
+ at g2 = external global i32, align 4
+ at g3 = external global i32, align 4
+ at g4 = external thread_local global i32, align 4
+
+define i32* @test3(i32 %n) {
+entry:
+  switch i32 %n, label %sw.default [
+    i32 0, label %sw.bb
+    i32 1, label %sw.bb1
+    i32 2, label %sw.bb2
+  ]
+
+sw.bb:
+  br label %return
+
+sw.bb1:
+  br label %return
+
+sw.bb2:
+  br label %return
+
+sw.default:
+  br label %return
+
+return:
+  %retval.0 = phi i32* [ @g4, %sw.default ], [ getelementptr inbounds (i32, i32* inttoptr (i32 mul (i32 ptrtoint (i32* @g3 to i32), i32 2) to i32*), i32 1), %sw.bb2 ], [ @g2, %sw.bb1 ], [ @g1, %sw.bb ]
+  ret i32* %retval.0
+}
Index: lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyCFG.cpp
+++ lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4445,9 +4445,12 @@
       !isa<UndefValue>(C) && !isa<ConstantExpr>(C))
     return false;
 
-  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
+  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
     if (!CE->isGEPWithNoNotionalOverIndexing())
       return false;
+    if (!ValidLookupTableConstant(CE->getOperand(0), TTI))
+      return false;
+  }
 
   if (!TTI.shouldBuildLookupTablesForConstant(C))
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25550.74627.patch
Type: text/x-patch
Size: 1925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161014/02ae9afd/attachment.bin>


More information about the llvm-commits mailing list