Skip to content

Commit

Permalink
SelectionDAG: allow FP extensions when folding extract/insert.
Browse files Browse the repository at this point in the history
Before, we were trying to sign extend half -> float, and asserted in getNode.
  • Loading branch information
TNorthover committed Jun 28, 2022
1 parent 22b8f35 commit 4aafebc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -6149,6 +6149,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (N1Op2C->getZExtValue() == N2C->getZExtValue()) {
if (VT == N1.getOperand(1).getValueType())
return N1.getOperand(1);
if (VT.isFloatingPoint()) {
assert(VT.getSizeInBits() > N1.getOperand(1).getValueType().getSizeInBits());
return getFPExtendOrRound(N1.getOperand(1), DL, VT);
}
return getSExtOrTrunc(N1.getOperand(1), DL, VT);
}
return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, N1.getOperand(0), N2);
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/ARM/arm-half-promote.ll
Expand Up @@ -79,3 +79,16 @@ define fastcc { <8 x half>, <8 x half> } @f3() {
ret { <8 x half>, <8 x half> } zeroinitializer
}

define void @extract_insert(ptr %dst) optnone noinline {
; CHECK-LABEL: extract_insert:
; CHECK: vmov.i32 d0, #0x0
; CHECK: vcvtb.f16.f32 s0, s0
; CHECK: vmov r1, s0
; CHECK: strh r1, [r0]
%splat.splatinsert = insertelement <1 x half> zeroinitializer, half 0xH0000, i32 0
br label %next

next:
store <1 x half> %splat.splatinsert, ptr %dst
ret void
}

0 comments on commit 4aafebc

Please sign in to comment.