diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index b912baef6188..fd9aff0f9fef 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -6324,6 +6324,9 @@ static bool validLookupTableConstant(Constant *C, const TargetTransformInfo &TTI !isa(C) && !isa(C)) return false; + if (C->getType()->isVectorTy()) + return false; + if (ConstantExpr *CE = dyn_cast(C)) { // Pointer casts and in-bounds GEPs will not prohibit the backend from // materializing the array of constants. diff --git a/llvm/test/Transforms/SimplifyCFG/AArch64/switch-to-lookup-table-vector-splat.ll b/llvm/test/Transforms/SimplifyCFG/AArch64/switch-to-lookup-table-vector-splat.ll new file mode 100644 index 000000000000..6a14c6a909f9 --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/AArch64/switch-to-lookup-table-vector-splat.ll @@ -0,0 +1,47 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 +; RUN: opt -passes='simplifycfg' -S < %s | FileCheck %s +; RUN: opt -passes='simplifycfg' -use-constant-fp-for-fixed-length-splat -S < %s | FileCheck %s + +target triple = "aarch64-unknown-linux-gnu" + +define <4 x float> @no_switch_to_lookup_table_vector_splat(i32 %c) { +; CHECK-LABEL: define <4 x float> @no_switch_to_lookup_table_vector_splat( +; CHECK-SAME: i32 [[C:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: switch i32 [[C]], label %[[DEFAULT:.*]] [ +; CHECK-NEXT: i32 0, label %[[RET:.*]] +; CHECK-NEXT: i32 1, label %[[BB1:.*]] +; CHECK-NEXT: i32 2, label %[[BB2:.*]] +; CHECK-NEXT: ] +; CHECK: [[BB1]]: +; CHECK-NEXT: br label %[[RET]] +; CHECK: [[BB2]]: +; CHECK-NEXT: br label %[[RET]] +; CHECK: [[DEFAULT]]: +; CHECK-NEXT: unreachable +; CHECK: [[RET]]: +; CHECK-NEXT: [[PHI:%.*]] = phi <4 x float> [ splat (float 3.000000e+00), %[[BB2]] ], [ splat (float 2.000000e+00), %[[BB1]] ], [ splat (float 1.000000e+00), %[[ENTRY]] ] +; CHECK-NEXT: ret <4 x float> [[PHI]] +entry: + switch i32 %c, label %default [ + i32 0, label %bb0 + i32 1, label %bb1 + i32 2, label %bb2 + ] + +bb0: + br label %ret + +bb1: + br label %ret + +bb2: + br label %ret + +default: + unreachable + +ret: + %phi = phi <4 x float> [ splat (float 1.0), %bb0 ], [ splat (float 2.0), %bb1 ], [ splat (float 3.0), %bb2 ] + ret <4 x float> %phi +}