Index: llvm/lib/Target/ARM/ARMInstrMVE.td =================================================================== --- llvm/lib/Target/ARM/ARMInstrMVE.td +++ llvm/lib/Target/ARM/ARMInstrMVE.td @@ -1953,6 +1953,41 @@ def MVE_VQNEGs16 : MVE_VQABSNEG<"vqneg", "s16", 0b01, 0b1>; def MVE_VQNEGs32 : MVE_VQABSNEG<"vqneg", "s32", 0b10, 0b1>; +// 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) + let Predicates = [HasMVEInt] in { + def : Pat<(VTI.Vec (vselect + (VTI.Pred (ARMvcmpz (VTI.Vec MQPR:$reg), (i32 12))), + (VTI.Vec MQPR:$reg), + (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 (vqabs_instruction (VTI.Vec MQPR:$reg)))>; + } +} + +defm MVE_VQABS_Ps8 : vqabs_pattern; +defm MVE_VQABS_Ps16 : vqabs_pattern; +defm MVE_VQABS_Ps32 : vqabs_pattern; + class MVE_mod_imm cmode, bit op, dag iops, list pattern=[]> : MVE_p<(outs MQPR:$Qd), iops, NoItinerary, iname, suffix, "$Qd, $imm", Index: llvm/test/CodeGen/Thumb2/vqabs.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/Thumb2/vqabs.ll @@ -0,0 +1,50 @@ +; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi -mattr=+mve %s -o - | FileCheck %s + +define arm_aapcs_vfpcc <16 x i8> @vqabs_test16(<16 x i8> %A) nounwind { +; CHECK-LABEL: vqabs_test16: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqabs.s8 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp sgt <16 x i8> %A, zeroinitializer + %1 = icmp eq <16 x i8> %A, + %2 = sub nsw <16 x i8> zeroinitializer, %A + %3 = select <16 x i1> %1, <16 x i8> , <16 x i8> %2 + %4 = select <16 x i1> %0, <16 x i8> %A, <16 x i8> %3 + + ret <16 x i8> %4 +} + +define arm_aapcs_vfpcc <8 x i16> @vqabs_test8(<8 x i16> %A) nounwind { +; CHECK-LABEL: vqabs_test8: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqabs.s16 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp sgt <8 x i16> %A, zeroinitializer + %1 = icmp eq <8 x i16> %A, + %2 = sub nsw <8 x i16> zeroinitializer, %A + %3 = select <8 x i1> %1, <8 x i16> , <8 x i16> %2 + %4 = select <8 x i1> %0, <8 x i16> %A, <8 x i16> %3 + + ret <8 x i16> %4 +} + +define arm_aapcs_vfpcc <4 x i32> @vqabs_test4(<4 x i32> %A) nounwind { +; CHECK-LABEL: vqabs_test4: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT: vqabs.s32 q0, q0 +; CHECK-NEXT: bx lr +entry: + + %0 = icmp sgt <4 x i32> %A, zeroinitializer + %1 = icmp eq <4 x i32> %A, + %2 = sub nsw <4 x i32> zeroinitializer, %A + %3 = select <4 x i1> %1, <4 x i32> , <4 x i32> %2 + %4 = select <4 x i1> %0, <4 x i32> %A, <4 x i32> %3 + + ret <4 x i32> %4 +} +