[SelectionDAG] Don't allow type legalization to create noop VP_TRUNCATE.
authorCraig Topper <craig.topper@sifive.com>
Tue, 13 Jun 2023 19:46:26 +0000 (12:46 -0700)
committerCraig Topper <craig.topper@sifive.com>
Tue, 13 Jun 2023 19:51:24 +0000 (12:51 -0700)
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.

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

index c9d15fc..c947293 100644 (file)
@@ -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.
index f628ac9..a5f61ca 100644 (file)
@@ -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
+}