[llvm] r274569 - DAGCombiner: Fold away vector extract of insert with the same index

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 22:49:11 PDT 2016


Hi,

I wrote this TR for the crash:

https://llvm.org/bugs/show_bug.cgi?id=28444

Regards,
Mikael

On 07/06/2016 11:21 AM, Mikael Holmén via llvm-commits wrote:
> Hi Matt and Nadav,
>
> This commit seems to make the X86 backend crash on the attached input.
>
> llc -march=x86-64 -mcpu=corei7 red.ll
>
> [...]
>
> === autogen_SD13436
> Initial selection DAG: BB#0 'autogen_SD13436:BB'
> SelectionDAG has 14 nodes:
>    t0: ch = EntryToken
>    t2: i32,ch = CopyFromReg t0, Register:i32 %vreg1
>    t7: i32 = Constant<0>
>          t4: i1 = setcc t2, t2, setult:ch
>          t9: v1i1 = insert_vector_elt undef:v1i1, Constant:i1<-1>,
> Constant:i64<0>
>        t10: v1i1 = select t4, undef:v1i1, t9
>      t11: i8 = extract_vector_elt t10, Constant:i64<0>
>    t13: ch = CopyToReg t0, Register:i8 %vreg0, t11
>
>
>
> Combining: t13: ch = CopyToReg t0, Register:i8 %vreg0, t11
>
> Combining: t12: i8 = Register %vreg0
>
> Combining: t11: i8 = extract_vector_elt t10, Constant:i64<0>
>
> Combining: t10: v1i1 = select t4, undef:v1i1, t9
>   ... into: t9: v1i1 = insert_vector_elt undef:v1i1, Constant:i1<-1>,
> Constant:i64<0>
>
> Combining: t11: i8 = extract_vector_elt t9, Constant:i64<0>
>   ... into: t6: i1 = Constant<-1>
> llc: ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6357: void
> llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode *, llvm::SDNode *):
> Assertion `(!From->hasAnyUseOfValue(i) || From->getValueType(i) ==
> To->getValueType(i)) && "Cannot use this version of
> ReplaceAllUsesWith!"' failed.
> #0 0x000000000254acbf llvm::sys::PrintStackTrace(llvm::raw_ostream&)
> /data/repo/llvm-patch/build-all-Debug/../lib/Support/Unix/Signals.inc:402:5
> #1 0x000000000254b1c9 PrintStackTraceSignalHandler(void*)
> /data/repo/llvm-patch/build-all-Debug/../lib/Support/Unix/Signals.inc:470:1
> #2 0x0000000002549823 llvm::sys::RunSignalHandlers()
> /data/repo/llvm-patch/build-all-Debug/../lib/Support/Signals.cpp:45:5
> #3 0x000000000254b7fe SignalHandler(int)
> /data/repo/llvm-patch/build-all-Debug/../lib/Support/Unix/Signals.inc:256:1
> #4 0x00007f3e718d0330 __restore_rt
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
> #5 0x00007f3e704c3c37 gsignal
> /build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
>
> #6 0x00007f3e704c7028 abort
> /build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
> #7 0x00007f3e704bcbf6 __assert_fail_base
> /build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
> #8 0x00007f3e704bcca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
> #9 0x000000000234de74
> llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDNode*)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6355:5
>
> #10 0x00000000021e51cb (anonymous
> namespace)::DAGCombiner::Run(llvm::CombineLevel)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1337:7
>
> #11 0x00000000021e4a92 llvm::SelectionDAG::Combine(llvm::CombineLevel,
> llvm::AAResults&, llvm::CodeGenOpt::Level)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/DAGCombiner.cpp:15038:3
>
> #12 0x000000000239e004 llvm::SelectionDAGISel::CodeGenAndEmitDAG()
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:755:5
>
> #13 0x000000000239dbee
> llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::Instruction
> const>, llvm::ilist_iterator<llvm::Instruction const>, bool&)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:680:1
>
> #14 0x000000000239da33
> llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1485:5
>
> #15 0x000000000239b81b
> llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:505:36
>
> #16 0x00000000015ae72b (anonymous
> namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /data/repo/llvm-patch/build-all-Debug/../lib/Target/X86/X86ISelDAGToDAG.cpp:175:25
>
> #17 0x0000000001c0e27b
> llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
> /data/repo/llvm-patch/build-all-Debug/../lib/CodeGen/MachineFunctionPass.cpp:60:8
>
> #18 0x0000000001f9af8d
> llvm::FPPassManager::runOnFunction(llvm::Function&)
> /data/repo/llvm-patch/build-all-Debug/../lib/IR/LegacyPassManager.cpp:1526:23
>
> #19 0x0000000001f9b2c5 llvm::FPPassManager::runOnModule(llvm::Module&)
> /data/repo/llvm-patch/build-all-Debug/../lib/IR/LegacyPassManager.cpp:1547:16
>
> #20 0x0000000001f9baae (anonymous
> namespace)::MPPassManager::runOnModule(llvm::Module&)
> /data/repo/llvm-patch/build-all-Debug/../lib/IR/LegacyPassManager.cpp:1603:23
>
> #21 0x0000000001f9b5ab llvm::legacy::PassManagerImpl::run(llvm::Module&)
> /data/repo/llvm-patch/build-all-Debug/../lib/IR/LegacyPassManager.cpp:1706:16
>
> #22 0x0000000001f9bff1 llvm::legacy::PassManager::run(llvm::Module&)
> /data/repo/llvm-patch/build-all-Debug/../lib/IR/LegacyPassManager.cpp:1737:3
>
> #23 0x000000000086ca58 compileModule(char**, llvm::LLVMContext&)
> /data/repo/llvm-patch/build-all-Debug/../tools/llc/llc.cpp:483:42
> #24 0x000000000086af31 main
> /data/repo/llvm-patch/build-all-Debug/../tools/llc/llc.cpp:260:13
> #25 0x00007f3e704aef45 __libc_start_main
> /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
> #26 0x000000000086aae4 _start (build-all-Debug/bin/llc+0x86aae4)
> Stack dump:
> 0.      Program arguments: build-all-Debug/bin/llc -march=x86-64
> -mcpu=corei7 red.ll -debug
> 1.      Running pass 'Function Pass Manager' on module 'red.ll'.
> 2.      Running pass 'X86 DAG->DAG Instruction Selection' on function
> '@autogen_SD13436'
>
> In the debugger:
>
> #4  0x000000000234de74 in llvm::SelectionDAG::ReplaceAllUsesWith
> (this=0x3f2e490, From=0x3f87280, To=0x3f87050) at
> ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6355
> 6355        assert((!From->hasAnyUseOfValue(i) ||
> (gdb) l
> 6352    void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To) {
> 6353    #ifndef NDEBUG
> 6354      for (unsigned i = 0, e = From->getNumValues(); i != e; ++i)
> 6355        assert((!From->hasAnyUseOfValue(i) ||
> 6356                From->getValueType(i) == To->getValueType(i)) &&
> 6357               "Cannot use this version of ReplaceAllUsesWith!");
> 6358    #endif
> 6359
> (gdb) p i
> $1 = 0
> (gdb) p From->hasAnyUseOfValue(i)
> $2 = true
> (gdb) p From->getValueType(i)
> $3 = {V = {SimpleTy = llvm::MVT::i8}, LLVMTy = 0x0}
> (gdb) p To->getValueType(i)
> $4 = {V = {SimpleTy = llvm::MVT::i1}, LLVMTy = 0x0}
> (gdb) call From->dump()
> t11: i8 = extract_vector_elt t9, Constant:i64<0>
> (gdb) call To->dump()
> t6: i1 = Constant<-1>
>
> The input file was generated with llvm-stress and then bugpoint and
> manually reduced.
>
> Regards,
> Mikael
>
> On 07/05/2016 08:25 PM, Matt Arsenault via llvm-commits wrote:
>> Author: arsenm
>> Date: Tue Jul  5 13:25:02 2016
>> New Revision: 274569
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=274569&view=rev
>> Log:
>> DAGCombiner: Fold away vector extract of insert with the same index
>>
>> This only really matters when the index is non-constant since the
>> constant case already gets taken care of by other combines.
>>
>> Added:
>>      llvm/trunk/test/CodeGen/AMDGPU/vector-extract-insert.ll
>> Modified:
>>      llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>>
>> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=274569&r1=274568&r2=274569&view=diff
>>
>> ==============================================================================
>>
>> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Jul  5
>> 13:25:02 2016
>> @@ -12397,6 +12397,14 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR
>>         return DAG.getNode(ISD::TRUNCATE, SDLoc(N), NVT, BCSrc);
>>     }
>>
>> +  // extract_vector_elt (insert_vector_elt vec, val, idx), idx) -> val
>> +  //
>> +  // This only really matters if the index is non-constant since
>> other combines
>> +  // on the constant elements already work.
>> +  if (InVec.getOpcode() == ISD::INSERT_VECTOR_ELT &&
>> +      EltNo == InVec.getOperand(2))
>> +    return InVec.getOperand(1);
>> +
>>     // Transform: (EXTRACT_VECTOR_ELT( VECTOR_SHUFFLE )) ->
>> EXTRACT_VECTOR_ELT.
>>     // We only perform this optimization before the op legalization
>> phase because
>>     // we may introduce new vector instructions which are not backed
>> by TD
>>
>> Added: llvm/trunk/test/CodeGen/AMDGPU/vector-extract-insert.ll
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/vector-extract-insert.ll?rev=274569&view=auto
>>
>> ==============================================================================
>>
>> --- llvm/trunk/test/CodeGen/AMDGPU/vector-extract-insert.ll (added)
>> +++ llvm/trunk/test/CodeGen/AMDGPU/vector-extract-insert.ll Tue Jul  5
>> 13:25:02 2016
>> @@ -0,0 +1,66 @@
>> +; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck
>> -check-prefix=GCN %s
>> +
>> +; Test that when extracting the same unknown vector index from an
>> +; insertelement the dynamic indexing is folded away.
>> +
>> +declare i32 @llvm.amdgcn.workitem.id.x() #0
>> +
>> +; No dynamic indexing required
>> +; GCN-LABEL: {{^}}extract_insert_same_dynelt_v4i32:
>> +; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}}
>> +; GCN-NOT buffer_load_dword
>> +; GCN-NOT: [[VAL]]
>> +; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]]
>> +; GCN-NOT: [[VVAL]]
>> +; GCN: buffer_store_dword [[VVAL]]
>> +define void @extract_insert_same_dynelt_v4i32(i32 addrspace(1)* %out,
>> <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx) #1 {
>> +  %id = call i32 @llvm.amdgcn.workitem.id.x()
>> +  %id.ext = sext i32 %id to i64
>> +  %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)*
>> %in, i64 %id.ext
>> +  %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64
>> %id.ext
>> +  %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
>> +  %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx
>> +  %extract = extractelement <4 x i32> %insert, i32 %idx
>> +  store i32 %extract, i32 addrspace(1)* %gep.out
>> +  ret void
>> +}
>> +
>> +; GCN-LABEL: {{^}}extract_insert_different_dynelt_v4i32:
>> +; GCN: buffer_load_dwordx4
>> +; GCN: v_movreld_b32
>> +; GCN: v_movrels_b32
>> +; GCN: buffer_store_dword v
>> +define void @extract_insert_different_dynelt_v4i32(i32 addrspace(1)*
>> %out, <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx0, i32 %idx1) #1 {
>> +  %id = call i32 @llvm.amdgcn.workitem.id.x()
>> +  %id.ext = sext i32 %id to i64
>> +  %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)*
>> %in, i64 %id.ext
>> +  %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64
>> %id.ext
>> +  %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
>> +  %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx0
>> +  %extract = extractelement <4 x i32> %insert, i32 %idx1
>> +  store i32 %extract, i32 addrspace(1)* %gep.out
>> +  ret void
>> +}
>> +
>> +; GCN-LABEL: {{^}}extract_insert_same_elt2_v4i32:
>> +; GCN: s_load_dword [[VAL:s[0-9]+]], s{{\[[0-9]+:[0-9]+\]}}, 0xd{{$}}
>> +; GCN-NOT buffer_load_dword
>> +; GCN-NOT: [[VAL]]
>> +; GCN: v_mov_b32_e32 [[VVAL:v[0-9]+]], [[VAL]]
>> +; GCN-NOT: [[VVAL]]
>> +; GCN: buffer_store_dword [[VVAL]]
>> +define void @extract_insert_same_elt2_v4i32(i32 addrspace(1)* %out,
>> <4 x i32> addrspace(1)* %in, i32 %val, i32 %idx) #1 {
>> +  %id = call i32 @llvm.amdgcn.workitem.id.x()
>> +  %id.ext = sext i32 %id to i64
>> +  %gep.in = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)*
>> %in, i64 %id.ext
>> +  %gep.out = getelementptr inbounds i32, i32 addrspace(1)* %out, i64
>> %id.ext
>> +  %vec = load <4 x i32>, <4 x i32> addrspace(1)* %gep.in
>> +  %insert = insertelement <4 x i32> %vec, i32 %val, i32 %idx
>> +  %extract = extractelement <4 x i32> %insert, i32 %idx
>> +  store i32 %extract, i32 addrspace(1)* %gep.out
>> +  ret void
>> +}
>> +
>> +
>> +attributes #0 = { nounwind readnone }
>> +attributes #1 = { nounwind }
>> \ No newline at end of file
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list