diff --git a/llvm/lib/Target/ARM/ARMInstrMVE.td b/llvm/lib/Target/ARM/ARMInstrMVE.td --- a/llvm/lib/Target/ARM/ARMInstrMVE.td +++ b/llvm/lib/Target/ARM/ARMInstrMVE.td @@ -1961,12 +1961,13 @@ // int_min/int_max: vector containing INT_MIN/INT_MAX VTI.Size times // zero_vec: v4i32-initialized zero vector, potentially wrapped in a bitconvert -multiclass vqabs_pattern { - // The below tree can be replaced by a vqabs instruction, as it represents - // the following vectorized expression (r being the value in $reg): - // r > 0 ? r : (r == INT_MIN ? INT_MAX : -r) +multiclass vqabsneg_pattern { let Predicates = [HasMVEInt] in { + // The below tree can be replaced by a vqabs instruction, as it represents + // the following vectorized expression (r being the value in $reg): + // r > 0 ? r : (r == INT_MIN ? INT_MAX : -r) def : Pat<(VTI.Vec (vselect (VTI.Pred (ARMvcmpz (VTI.Vec MQPR:$reg), (i32 12))), (VTI.Vec MQPR:$reg), @@ -1975,24 +1976,31 @@ int_max, (sub (VTI.Vec zero_vec), (VTI.Vec MQPR:$reg)))))), (VTI.Vec (vqabs_instruction (VTI.Vec MQPR:$reg)))>; + // Similarly, this tree represents vqneg, i.e. the following vectorized expression: + // r == INT_MIN ? INT_MAX : -r + def : Pat<(VTI.Vec (vselect + (VTI.Pred (ARMvcmp (VTI.Vec MQPR:$reg), int_min, (i32 0))), + int_max, + (sub (VTI.Vec zero_vec), (VTI.Vec MQPR:$reg)))), + (VTI.Vec (vqneg_instruction (VTI.Vec MQPR:$reg)))>; } } -defm MVE_VQABS_Ps8 : vqabs_pattern; -defm MVE_VQABS_Ps16 : vqabs_pattern; +defm MVE_VQABSNEG_Ps16 : vqabsneg_pattern; -defm MVE_VQABS_Ps32 : vqabs_pattern; +defm MVE_VQABSNEG_Ps32 : vqabsneg_pattern; + MVE_VQABSs32, MVE_VQNEGs32>; class MVE_mod_imm cmode, bit op, dag iops, list pattern=[]> diff --git a/llvm/test/CodeGen/Thumb2/vqneg.ll b/llvm/test/CodeGen/Thumb2/vqneg.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/Thumb2/vqneg.ll @@ -0,0 +1,44 @@ +; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi -mattr=+mve %s -o - | FileCheck %s + +define arm_aapcs_vfpcc <16 x i8> @vqneg_test16(<16 x i8> %A) nounwind { +; CHECK-LABEL: vqneg_test16: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqneg.s8 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp eq <16 x i8> %A, + %1 = sub nsw <16 x i8> zeroinitializer, %A + %2 = select <16 x i1> %0, <16 x i8> , <16 x i8> %1 + + ret <16 x i8> %2 +} + +define arm_aapcs_vfpcc <8 x i16> @vqneg_test8(<8 x i16> %A) nounwind { +; CHECK-LABEL: vqneg_test8: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqneg.s16 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp eq <8 x i16> %A, + %1 = sub nsw <8 x i16> zeroinitializer, %A + %2 = select <8 x i1> %0, <8 x i16> , <8 x i16> %1 + + ret <8 x i16> %2 +} + +define arm_aapcs_vfpcc <4 x i32> @vqneg_test4(<4 x i32> %A) nounwind { +; CHECK-LABEL: vqneg_test4: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqneg.s32 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp eq <4 x i32> %A, + %1 = sub nsw <4 x i32> zeroinitializer, %A + %2 = select <4 x i1> %0, <4 x i32> , <4 x i32> %1 + + ret <4 x i32> %2 +} +