From: Craig Topper Date: Tue, 13 Jun 2023 19:46:26 +0000 (-0700) Subject: [SelectionDAG] Don't allow type legalization to create noop VP_TRUNCATE. X-Git-Tag: upstream/17.0.6~5225 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5cd198181f937417c988e82f50461adb29aef76;p=platform%2Fupstream%2Fllvm.git [SelectionDAG] Don't allow type legalization to create noop VP_TRUNCATE. Type legalization may need to promote the result to the same type as the input. Instead of forming a vp_truncate with the same source and dest type, don't create any vp_truncate. Handling in getNode like is done for ISD::TRUNCATE. --- diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index c9d15fc..c947293 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6922,6 +6922,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, if (N1.getValueType() == VT) return N1; break; + case ISD::VP_TRUNCATE: + // Don't create noop vp_truncate. + if (N1.getValueType() == VT) + return N1; + break; } // Memoize node if it doesn't produce a flag. diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vector-trunc-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vector-trunc-vp.ll index f628ac9..a5f61ca 100644 --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vector-trunc-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vector-trunc-vp.ll @@ -512,3 +512,13 @@ define <32 x i32> @vtrunc_v32i32_v32i64(<32 x i64> %a, <32 x i1> %m, i32 zeroext %v = call <32 x i32> @llvm.vp.trunc.v32i32.v32i64(<32 x i64> %a, <32 x i1> %m, i32 %vl) ret <32 x i32> %v } + +declare <2 x i7> @llvm.vp.trunc.v2i7.v2i8(<2 x i8>, <2 x i1>, i32) + +define <2 x i7> @vtrunc_v2i7_v2i8(<2 x i8> %a, <2 x i1> %m, i32 zeroext %vl) { +; CHECK-LABEL: vtrunc_v2i7_v2i8: +; CHECK: # %bb.0: +; CHECK-NEXT: ret + %v = call <2 x i7> @llvm.vp.trunc.v2i7.v2i8(<2 x i8> %a, <2 x i1> %m, i32 %vl) + ret <2 x i7> %v +}