[AArch64][GlobalISel] Fix crash on lowering <1 x half> types.
authorAmara Emerson <amara@apple.com>
Tue, 16 Mar 2021 06:27:10 +0000 (23:27 -0700)
committerAmara Emerson <amara@apple.com>
Tue, 16 Mar 2021 06:27:43 +0000 (23:27 -0700)
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/test/CodeGen/AArch64/GlobalISel/call-lowering-vectors.ll

index d16e2fd..dbe5f56 100644 (file)
@@ -357,9 +357,14 @@ bool AArch64CallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
               return false;
             }
           } else {
-            // A scalar extend.
-            CurVReg =
-                MIRBuilder.buildInstr(ExtendOp, {NewLLT}, {CurVReg}).getReg(0);
+            // If the split EVT was a <1 x T> vector, and NewVT is T, then we
+            // don't have to do anything since we don't distinguish between the
+            // two.
+            if (NewLLT != MRI.getType(CurVReg)) {
+              // A scalar extend.
+              CurVReg = MIRBuilder.buildInstr(ExtendOp, {NewLLT}, {CurVReg})
+                            .getReg(0);
+            }
           }
         }
       }
index ee73e58..f34f098 100644 (file)
@@ -31,3 +31,16 @@ define i24 @test_v3i8(<3 x i8> %a) {
   ret i24 %res
 }
 
+
+define <1 x half> @test_v1s16(<1 x float> %x) {
+  ; CHECK-LABEL: name: test_v1s16
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: $d0
+  ; CHECK:   [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0
+  ; CHECK:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[COPY]](<2 x s32>)
+  ; CHECK:   [[FPTRUNC:%[0-9]+]]:_(s16) = G_FPTRUNC [[UV]](s32)
+  ; CHECK:   $h0 = COPY [[FPTRUNC]](s16)
+  ; CHECK:   RET_ReallyLR implicit $h0
+  %tmp = fptrunc <1 x float> %x to <1 x half>
+  ret <1 x half> %tmp
+}