Skip to content

Commit a5cd198

Browse files
committed
[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.
1 parent f231829 commit a5cd198

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6922,6 +6922,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
69226922
if (N1.getValueType() == VT)
69236923
return N1;
69246924
break;
6925+
case ISD::VP_TRUNCATE:
6926+
// Don't create noop vp_truncate.
6927+
if (N1.getValueType() == VT)
6928+
return N1;
6929+
break;
69256930
}
69266931

69276932
// Memoize node if it doesn't produce a flag.

llvm/test/CodeGen/RISCV/rvv/fixed-vector-trunc-vp.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,13 @@ define <32 x i32> @vtrunc_v32i32_v32i64(<32 x i64> %a, <32 x i1> %m, i32 zeroext
512512
%v = call <32 x i32> @llvm.vp.trunc.v32i32.v32i64(<32 x i64> %a, <32 x i1> %m, i32 %vl)
513513
ret <32 x i32> %v
514514
}
515+
516+
declare <2 x i7> @llvm.vp.trunc.v2i7.v2i8(<2 x i8>, <2 x i1>, i32)
517+
518+
define <2 x i7> @vtrunc_v2i7_v2i8(<2 x i8> %a, <2 x i1> %m, i32 zeroext %vl) {
519+
; CHECK-LABEL: vtrunc_v2i7_v2i8:
520+
; CHECK: # %bb.0:
521+
; CHECK-NEXT: ret
522+
%v = call <2 x i7> @llvm.vp.trunc.v2i7.v2i8(<2 x i8> %a, <2 x i1> %m, i32 %vl)
523+
ret <2 x i7> %v
524+
}

0 commit comments

Comments
 (0)