diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 6a4ff741af10a..2e1f4b7e5b374 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5246,8 +5246,12 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, // Ensure that the element index is in bounds. EVT VecVT = Op.getOperand(0).getValueType(); SDValue Idx = Op.getOperand(Opcode == ISD::INSERT_VECTOR_ELT ? 2 : 1); - KnownBits KnownIdx = computeKnownBits(Idx, Depth + 1); - return KnownIdx.getMaxValue().uge(VecVT.getVectorMinNumElements()); + if (isGuaranteedNotToBeUndefOrPoison(Idx, DemandedElts, PoisonOnly, + Depth + 1)) { + KnownBits KnownIdx = computeKnownBits(Idx, Depth + 1); + return KnownIdx.getMaxValue().uge(VecVT.getVectorMinNumElements()); + } + return true; } case ISD::VECTOR_SHUFFLE: { diff --git a/llvm/test/CodeGen/X86/pr92569.ll b/llvm/test/CodeGen/X86/pr92569.ll new file mode 100644 index 0000000000000..f91063089e3a9 --- /dev/null +++ b/llvm/test/CodeGen/X86/pr92569.ll @@ -0,0 +1,29 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 +; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s + +define void @PR92569(i64 %arg, <8 x i8> %arg1) { +; CHECK-LABEL: PR92569: +; CHECK: # %bb.0: +; CHECK-NEXT: testq %rdi, %rdi +; CHECK-NEXT: je .LBB0_1 +; CHECK-NEXT: # %bb.2: # %cond.false +; CHECK-NEXT: rep bsfq %rdi, %rax +; CHECK-NEXT: jmp .LBB0_3 +; CHECK-NEXT: .LBB0_1: +; CHECK-NEXT: movl $64, %eax +; CHECK-NEXT: .LBB0_3: # %cond.end +; CHECK-NEXT: shrb $3, %al +; CHECK-NEXT: movaps %xmm0, -{{[0-9]+}}(%rsp) +; CHECK-NEXT: movzbl %al, %eax +; CHECK-NEXT: movzbl -24(%rsp,%rax), %eax +; CHECK-NEXT: movl %eax, 0 +; CHECK-NEXT: retq + %cttz = call i64 @llvm.cttz.i64(i64 %arg, i1 false) + %trunc = trunc i64 %cttz to i8 + %lshr = lshr i8 %trunc, 3 + %extractelement = extractelement <8 x i8> %arg1, i8 %lshr + %freeze = freeze i8 %extractelement + %zext = zext i8 %freeze to i32 + store i32 %zext, ptr addrspace(1) null, align 4 + ret void +}