SelectionDAG: allow FP extensions when folding extract/insert.
authorTim Northover <tnorthover@apple.com>
Tue, 28 Jun 2022 10:02:02 +0000 (11:02 +0100)
committerTim Northover <tnorthover@apple.com>
Tue, 28 Jun 2022 11:08:35 +0000 (12:08 +0100)
Before, we were trying to sign extend half -> float, and asserted in getNode.

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/ARM/arm-half-promote.ll

index 213874fb49337c6098ac06f1abb04120391ac5fa..bc1011b69c9df4a7463c48b3c0b616e21643197e 100644 (file)
@@ -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);
index f3c9a9e081ba87ef495bde1225ffd3d2d7d98a9f..d6a8a9b9538f174c61ed5db835c2d2a4a071be8f 100644 (file)
@@ -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
+}