Index: lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -408,6 +408,10 @@ case ISD::ZERO_EXTEND: case ISD::SIGN_EXTEND: case ISD::TRUNCATE: + case ISD::FP_TO_SINT: + case ISD::FP_TO_UINT: + case ISD::SINT_TO_FP: + case ISD::UINT_TO_FP: Res = ScalarizeVecOp_UnaryOp(N); break; case ISD::CONCAT_VECTORS: @@ -451,11 +455,11 @@ N->getValueType(0), Elt); } -/// ScalarizeVecOp_EXTEND - If the value to extend is a vector that needs -/// to be scalarized, it must be <1 x ty>. Extend the element instead. +/// ScalarizeVecOp_UnaryOp - If the input is a vector that needs to be +/// scalarized, it must be <1 x ty>. Do the operation on the element instead. SDValue DAGTypeLegalizer::ScalarizeVecOp_UnaryOp(SDNode *N) { assert(N->getValueType(0).getVectorNumElements() == 1 && - "Unexected vector type!"); + "Unexpected vector type!"); SDValue Elt = GetScalarizedVector(N->getOperand(0)); SDValue Op = DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0).getScalarType(), Elt); Index: test/CodeGen/AArch64/fpconv-vector-op-scalarize.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/fpconv-vector-op-scalarize.ll @@ -0,0 +1,34 @@ +; RUN: llc < %s -mtriple=arm64-apple-darwin | FileCheck %s + +; PR20778 +; Check that the legalizer doesn't crash when scalarizing FP conversion +; instructions' operands. The operands are all illegal on AArch64, +; ensuring they are legalized. The results are all legal. + +define <1 x double> @test_sitofp(<1 x i1> %in) { +; CHECK-LABEL: test_sitofp: +entry: + %0 = sitofp <1 x i1> %in to <1 x double> + ret <1 x double> %0 +} + +define <1 x double> @test_uitofp(<1 x i1> %in) { +; CHECK-LABEL: test_uitofp: +entry: + %0 = uitofp <1 x i1> %in to <1 x double> + ret <1 x double> %0 +} + +define <1 x i64> @test_fptosi(<1 x fp128> %in) { +; CHECK-LABEL: test_fptosi: +entry: + %0 = fptosi <1 x fp128> %in to <1 x i64> + ret <1 x i64> %0 +} + +define <1 x i64> @test_fptoui(<1 x fp128> %in) { +; CHECK-LABEL: test_fptoui: +entry: + %0 = fptoui <1 x fp128> %in to <1 x i64> + ret <1 x i64> %0 +}