From: Paul Walker Date: Mon, 6 Jun 2022 03:07:52 +0000 (+0100) Subject: [SelectionDAG] Remove invalid TypeSize conversion from WidenVecOp_BITCAST. X-Git-Tag: upstream/15.0.7~5109 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10d55c4634fab8758cbe972f7a252b2e47ca32db;p=platform%2Fupstream%2Fllvm.git [SelectionDAG] Remove invalid TypeSize conversion from WidenVecOp_BITCAST. Differential Revision: https://reviews.llvm.org/D127322 --- diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index a40cc69..f1d4682 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -5712,11 +5712,12 @@ SDValue DAGTypeLegalizer::WidenVecOp_BITCAST(SDNode *N) { SDLoc dl(N); // Check if we can convert between two legal vector types and extract. - unsigned InWidenSize = InWidenVT.getSizeInBits(); - unsigned Size = VT.getSizeInBits(); + TypeSize InWidenSize = InWidenVT.getSizeInBits(); + TypeSize Size = VT.getSizeInBits(); // x86mmx is not an acceptable vector element type, so don't try. - if (InWidenSize % Size == 0 && !VT.isVector() && VT != MVT::x86mmx) { - unsigned NewNumElts = InWidenSize / Size; + if (!VT.isVector() && VT != MVT::x86mmx && + InWidenSize.hasKnownScalarFactor(Size)) { + unsigned NewNumElts = InWidenSize.getKnownScalarFactor(Size); EVT NewVT = EVT::getVectorVT(*DAG.getContext(), VT, NewNumElts); if (TLI.isTypeLegal(NewVT)) { SDValue BitOp = DAG.getNode(ISD::BITCAST, dl, NewVT, InOp); @@ -5731,9 +5732,11 @@ SDValue DAGTypeLegalizer::WidenVecOp_BITCAST(SDNode *N) { // having to copy via memory. if (VT.isVector()) { EVT EltVT = VT.getVectorElementType(); - unsigned EltSize = EltVT.getSizeInBits(); - if (InWidenSize % EltSize == 0) { - unsigned NewNumElts = InWidenSize / EltSize; + unsigned EltSize = EltVT.getFixedSizeInBits(); + if (InWidenSize.isKnownMultipleOf(EltSize)) { + ElementCount NewNumElts = + (InWidenVT.getVectorElementCount() * InWidenVT.getScalarSizeInBits()) + .divideCoefficientBy(EltSize); EVT NewVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NewNumElts); if (TLI.isTypeLegal(NewVT)) { SDValue BitOp = DAG.getNode(ISD::BITCAST, dl, NewVT, InOp); diff --git a/llvm/test/CodeGen/AArch64/sve-bitcast.ll b/llvm/test/CodeGen/AArch64/sve-bitcast.ll index 0227b89..40d57e4 100644 --- a/llvm/test/CodeGen/AArch64/sve-bitcast.ll +++ b/llvm/test/CodeGen/AArch64/sve-bitcast.ll @@ -874,7 +874,14 @@ define @bitcast_nxv2i32_to_nxv4f16( %v) #0 ret %bc } -; @bitcast_nxv1i64_to_nxv4f16 is missing +define @bitcast_nxv1i64_to_nxv4f16( %v) #0 { +; CHECK-LABEL: bitcast_nxv1i64_to_nxv4f16: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.s, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} define @bitcast_nxv2f32_to_nxv4f16( %v) #0 { ; CHECK-LABEL: bitcast_nxv2f32_to_nxv4f16: @@ -892,7 +899,14 @@ define @bitcast_nxv2f32_to_nxv4f16( %v) ret %bc } -; @bitcast_nxv1f64_to_nxv4f16 is missing +define @bitcast_nxv1f64_to_nxv4f16( %v) #0 { +; CHECK-LABEL: bitcast_nxv1f64_to_nxv4f16: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.s, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} define @bitcast_nxv4bf16_to_nxv4f16( %v) #0 { ; CHECK-LABEL: bitcast_nxv4bf16_to_nxv4f16: @@ -946,7 +960,14 @@ define @bitcast_nxv2i32_to_nxv2f32( %v) # ret %bc } -; @bitcast_nxv1i64_to_nxv2f32 is missing +define @bitcast_nxv1i64_to_nxv2f32( %v) #0 { +; CHECK-LABEL: bitcast_nxv1i64_to_nxv2f32: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.d, z0.s +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} define @bitcast_nxv4f16_to_nxv2f32( %v) #0 { ; CHECK-LABEL: bitcast_nxv4f16_to_nxv2f32: @@ -964,7 +985,14 @@ define @bitcast_nxv4f16_to_nxv2f32( %v) ret %bc } -; @bitcast_nxv1f64_to_nxv2f32 is missing +define @bitcast_nxv1f64_to_nxv2f32( %v) #0 { +; CHECK-LABEL: bitcast_nxv1f64_to_nxv2f32: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.d, z0.s +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} define @bitcast_nxv4bf16_to_nxv2f32( %v) #0 { ; CHECK-LABEL: bitcast_nxv4bf16_to_nxv2f32: @@ -986,13 +1014,67 @@ define @bitcast_nxv4bf16_to_nxv2f32( % ; bitcast to nxv1f64 ; -; @bitcast_nxv8i8_to_nxv1f64 is missing -; @bitcast_nxv4i16_to_nxv1f64 is missing -; @bitcast_nxv2i32_to_nxv1f64 is missing -; @bitcast_nxv1i64_to_nxv1f64 is missing -; @bitcast_nxv4f16_to_nxv1f64 is missing -; @bitcast_nxv2f32_to_nxv1f64 is missing -; @bitcast_nxv4bf16_to_nxv1f64 is missing +define @bitcast_nxv8i8_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv8i8_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv4i16_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv4i16_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv2i32_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv2i32_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv1i64_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv1i64_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv4f16_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv4f16_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv2f32_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv2f32_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} + +define @bitcast_nxv4bf16_to_nxv1f64( %v) #0 { +; CHECK-LABEL: bitcast_nxv4bf16_to_nxv1f64: +; CHECK: // %bb.0: +; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} ; ; bitcast to nxv4bf16 @@ -1038,7 +1120,14 @@ define @bitcast_nxv2i32_to_nxv4bf16( %v) ret %bc } -; @bitcast_nxv1i64_to_nxv4bf16 is missing +define @bitcast_nxv1i64_to_nxv4bf16( %v) #0 { +; CHECK-LABEL: bitcast_nxv1i64_to_nxv4bf16: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.s, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} define @bitcast_nxv4f16_to_nxv4bf16( %v) #0 { ; CHECK-LABEL: bitcast_nxv4f16_to_nxv4bf16: @@ -1064,7 +1153,14 @@ define @bitcast_nxv2f32_to_nxv4bf16( % ret %bc } -; @bitcast_nxv1f64_to_nxv4bf16 is missing +define @bitcast_nxv1f64_to_nxv4bf16( %v) #0 { +; CHECK-LABEL: bitcast_nxv1f64_to_nxv4bf16: +; CHECK: // %bb.0: +; CHECK-NEXT: uunpklo z0.s, z0.h +; CHECK-NEXT: ret + %bc = bitcast %v to + ret %bc +} ; ; bitcast to nxv4i8 @@ -1276,6 +1372,16 @@ define @bitcast_nxv2bf16_to_nxv2f16( %v } ; +; bitcast to nxv1f32 +; + +; @bitcast_nxv4i8_to_nxv1f32 is missing +; @bitcast_nxv2i16_to_nxv1f32 is missing +; @bitcast_nxv1i32_to_nxv1f32 is missing +; @bitcast_nxv2f16_to_nxv1f32 is missing +; @bitcast_nxv2bf16_to_nxv1f32 is missing + +; ; bitcast to nxv2bf16 ; @@ -1352,6 +1458,22 @@ define @bitcast_nxv2i8_to_nxv1i16( %v) #0 { ; @bitcast_nxv1bf16_to_nxv1i16 is missing ; +; bitcast to nxv1f16 +; + +; @bitcast_nxv2i8_to_nxv1f16 is missing +; @bitcast_nxv1i16_to_nxv1f16 is missing +; @bitcast_nxv1bf16_to_nxv1f16 is missing + +; +; bitcast to nxv1bf16 +; + +; @bitcast_nxv2i8_to_nxv1bf16 is missing +; @bitcast_nxv1i16_to_nxv1bf16 is missing +; @bitcast_nxv1f16_to_nxv1bf16 is missing + +; ; Other ;