diff --git a/llvm/lib/Target/Hexagon/HexagonPatterns.td b/llvm/lib/Target/Hexagon/HexagonPatterns.td index c54be2f16f1d..485e658e1c84 100644 --- a/llvm/lib/Target/Hexagon/HexagonPatterns.td +++ b/llvm/lib/Target/Hexagon/HexagonPatterns.td @@ -344,6 +344,13 @@ multiclass MinMax_pats; } +// Bitcasts between same-size vector types are no-ops, except for the +// actual type change. +multiclass NopCast_pat { + def: Pat<(Ty1 (bitconvert (Ty2 RC:$Val))), (Ty1 RC:$Val)>; + def: Pat<(Ty2 (bitconvert (Ty1 RC:$Val))), (Ty2 RC:$Val)>; +} + // Frags for commonly used SDNodes. def Add: pf2; def And: pf2; def Sra: pf2; @@ -427,17 +434,18 @@ def: Pat<(f32 (bitconvert I32:$v)), (F32:$v)>; def: Pat<(i64 (bitconvert F64:$v)), (I64:$v)>; def: Pat<(f64 (bitconvert I64:$v)), (F64:$v)>; -multiclass Cast_pat { - def: Pat<(Tb (bitconvert (Ta RC:$Rs))), (Tb RC:$Rs)>; - def: Pat<(Ta (bitconvert (Tb RC:$Rs))), (Ta RC:$Rs)>; -} - -// Bit convert vector types to integers. -defm: Cast_pat; -defm: Cast_pat; -defm: Cast_pat; -defm: Cast_pat; -defm: Cast_pat; +// Bit convert 32- and 64-bit types. +// All of these are bitcastable to one another: i32, v2i16, v4i8. +defm: NopCast_pat; +defm: NopCast_pat; +defm: NopCast_pat; +// All of these are bitcastable to one another: i64, v2i32, v4i16, v8i8. +defm: NopCast_pat; +defm: NopCast_pat; +defm: NopCast_pat; +defm: NopCast_pat; +defm: NopCast_pat; +defm: NopCast_pat; // --(3) Extend/truncate ------------------------------------------------- diff --git a/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td b/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td index 32e2260de07c..078a7135c55b 100644 --- a/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td +++ b/llvm/lib/Target/Hexagon/HexagonPatternsHVX.td @@ -160,23 +160,14 @@ let Predicates = [UseHVX] in { // Bitcasts between same-size vector types are no-ops, except for the // actual type change. -class Bitcast - : Pat<(ResTy (bitconvert (InpTy RC:$Val))), (ResTy RC:$Val)>; - let Predicates = [UseHVX] in { - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; + defm: NopCast_pat; + defm: NopCast_pat; + defm: NopCast_pat; - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; - def: Bitcast; + defm: NopCast_pat; + defm: NopCast_pat; + defm: NopCast_pat; } let Predicates = [UseHVX] in { diff --git a/llvm/test/CodeGen/Hexagon/isel-bitcast-v8i8-v4i16.ll b/llvm/test/CodeGen/Hexagon/isel-bitcast-v8i8-v4i16.ll new file mode 100644 index 000000000000..f45b1a77c6d7 --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/isel-bitcast-v8i8-v4i16.ll @@ -0,0 +1,13 @@ +; RUN: llc -march=hexagon < %s | FileCheck %s + +; Check that this doesn't fail to select instructions. +; CHECK: vsplath + +define <8 x i8> @fred(i16 %a0) #0 { + %t0 = insertelement <4 x i16> undef, i16 %a0, i32 0 + %t1 = shufflevector <4 x i16> %t0, <4 x i16> undef, <4 x i32> zeroinitializer + %t2 = bitcast <4 x i16> %t1 to <8 x i8> + ret <8 x i8> %t2 +} + +attributes #0 = { readnone nounwind "target-cpu"="hexagonv62" }