From 83259d70bb907d244dfaa8ea3bfd58ef8d942a80 Mon Sep 17 00:00:00 2001 From: Elena Demikhovsky Date: Tue, 28 Apr 2015 14:46:35 +0000 Subject: [PATCH] Fixed crash of variable shift inst on AVX2 https://llvm.org/bugs/show_bug.cgi?id=22955 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235993 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 4 +-- test/CodeGen/X86/shift-avx2-crash.ll | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 test/CodeGen/X86/shift-avx2-crash.ll diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index cf3165e7513..1797ce4a11f 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -16495,9 +16495,7 @@ static SDValue LowerScalarVariableShift(SDValue Op, SelectionDAG &DAG, } // Special case in 32-bit mode, where i64 is expanded into high and low parts. - if (!Subtarget->is64Bit() && - (VT == MVT::v2i64 || (Subtarget->hasInt256() && VT == MVT::v4i64) || - (Subtarget->hasAVX512() && VT == MVT::v8i64)) && + if (!Subtarget->is64Bit() && VT == MVT::v2i64 && Amt.getOpcode() == ISD::BITCAST && Amt.getOperand(0).getOpcode() == ISD::BUILD_VECTOR) { Amt = Amt.getOperand(0); diff --git a/test/CodeGen/X86/shift-avx2-crash.ll b/test/CodeGen/X86/shift-avx2-crash.ll new file mode 100755 index 00000000000..b23d6e3359e --- /dev/null +++ b/test/CodeGen/X86/shift-avx2-crash.ll @@ -0,0 +1,38 @@ +; RUN: llc < %s -mcpu=core-avx2 > /dev/null +; This test crashed on variable shift creation on AVX2 + +target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" +target triple = "i386-unknown-linux-gnu" + +define void @f_f(float* noalias nocapture %RET, float %aFOO, i32 %div) { +allocas: + %__idiv_table_u32_offset10_offset_load.i = add i64 0, -2 + br label %if_then18.i + +if_then18.i: + %aFOO_load_to_uint32 = fptoui float %aFOO to i32 + %aFOO_load_to_uint32_broadcast_init = insertelement <8 x i32> undef, i32 %aFOO_load_to_uint32, i32 0 + %aFOO_load_to_uint32_broadcast = shufflevector <8 x i32> %aFOO_load_to_uint32_broadcast_init, <8 x i32> undef, <8 x i32> zeroinitializer + + %multiplier_load_broadcast_init.i = insertelement <8 x i64> undef, i64 2, i32 0 + %multiplier_load_broadcast.i = shufflevector <8 x i64> %multiplier_load_broadcast_init.i, <8 x i64> undef, <8 x i32> zeroinitializer + %numerator_load_to_uint64.i = zext <8 x i32> %aFOO_load_to_uint32_broadcast to <8 x i64> + + ;if replace '%__idiv_table_u32_offset10_offset_load.i' with '-2' or remove 'if_then18.i' label the error disappears + %add__shift_load21.i = add i64 %__idiv_table_u32_offset10_offset_load.i, 32 + %add__shift_load21_broadcast_init.i = insertelement <8 x i64> undef, i64 %add__shift_load21.i, i32 0 + %add__shift_load21_broadcast.i = shufflevector <8 x i64> %add__shift_load21_broadcast_init.i, <8 x i64> undef, <8 x i32> zeroinitializer + + %mul_val_load_mult_load.i = mul <8 x i64> %numerator_load_to_uint64.i, %multiplier_load_broadcast.i + %bitop22.i = lshr <8 x i64> %mul_val_load_mult_load.i, %add__shift_load21_broadcast.i + %bitop22_to_uint32.i = trunc <8 x i64> %bitop22.i to <8 x i32> + br label %__fast_idiv___UM_vyuunu.exit + + +__fast_idiv___UM_vyuunu.exit: + %calltmp_to_float = uitofp <8 x i32> %bitop22_to_uint32.i to <8 x float> + %ptrcast = bitcast float* %RET to <8 x float>* + store <8 x float> %calltmp_to_float, <8 x float>* %ptrcast, align 4 + ret void +} + -- 2.34.1