diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp @@ -734,10 +734,19 @@ .libcall(); } + SmallVector LegalABSVectorTypes = PackedVectorAllTypeList; // FIXME: Legal types are only legal with NEON. getActionDefinitionsBuilder(G_ABS) - .lowerIf(isScalar(0)) - .legalFor(PackedVectorAllTypeList); + .lowerIf([=](const LegalityQuery &Query) { + if (HasCSSC && typeInSet(0, {s32, s64})(Query)) + return false; + return isScalar(0)(Query); + }) + .legalIf([=](const LegalityQuery &Query) { + if (HasCSSC && typeInSet(0, {s32, s64})(Query)) + return true; + return llvm::is_contained(LegalABSVectorTypes, Query.Types[0]); + }); getActionDefinitionsBuilder(G_VECREDUCE_FADD) // We only have FADDP to do reduction-like operations. Lower the rest. diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-abs.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-abs.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-abs.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-abs.mir @@ -1,5 +1,6 @@ # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py # RUN: llc -mtriple=aarch64 -run-pass=legalizer -global-isel-abort=1 %s -o - | FileCheck %s +# RUN: llc -mtriple=aarch64 -run-pass=legalizer -mattr=+cssc -global-isel-abort=1 %s -o - | FileCheck %s --check-prefix=CHECK-CSSC --- name: abs_s32 liveins: @@ -7,11 +8,15 @@ bb.0: ; CHECK-LABEL: name: abs_s32 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 - ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 31 - ; CHECK: [[ASHR:%[0-9]+]]:_(s32) = G_ASHR [[COPY]], [[C]](s64) - ; CHECK: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[ASHR]] - ; CHECK: [[XOR:%[0-9]+]]:_(s32) = G_XOR [[ADD]], [[ASHR]] - ; CHECK: $w0 = COPY [[XOR]](s32) + ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 31 + ; CHECK-NEXT: [[ASHR:%[0-9]+]]:_(s32) = G_ASHR [[COPY]], [[C]](s64) + ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[ASHR]] + ; CHECK-NEXT: [[XOR:%[0-9]+]]:_(s32) = G_XOR [[ADD]], [[ASHR]] + ; CHECK-NEXT: $w0 = COPY [[XOR]](s32) + ; CHECK-CSSC-LABEL: name: abs_s32 + ; CHECK-CSSC: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(s32) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $w0 = COPY [[ABS]](s32) %0:_(s32) = COPY $w0 %1:_(s32) = G_ABS %0(s32) $w0 = COPY %1(s32) @@ -23,11 +28,15 @@ bb.0: ; CHECK-LABEL: name: abs_s64 ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x0 - ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 63 - ; CHECK: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[COPY]], [[C]](s64) - ; CHECK: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[COPY]], [[ASHR]] - ; CHECK: [[XOR:%[0-9]+]]:_(s64) = G_XOR [[ADD]], [[ASHR]] - ; CHECK: $x0 = COPY [[XOR]](s64) + ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 63 + ; CHECK-NEXT: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[COPY]], [[C]](s64) + ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[COPY]], [[ASHR]] + ; CHECK-NEXT: [[XOR:%[0-9]+]]:_(s64) = G_XOR [[ADD]], [[ASHR]] + ; CHECK-NEXT: $x0 = COPY [[XOR]](s64) + ; CHECK-CSSC-LABEL: name: abs_s64 + ; CHECK-CSSC: [[COPY:%[0-9]+]]:_(s64) = COPY $x0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(s64) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $x0 = COPY [[ABS]](s64) %0:_(s64) = COPY $x0 %1:_(s64) = G_ABS %0(s64) $x0 = COPY %1(s64) @@ -41,10 +50,18 @@ ; CHECK-LABEL: name: abs_v4s16 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:_(<4 x s16>) = COPY $d0 - ; CHECK: [[ABS:%[0-9]+]]:_(<4 x s16>) = G_ABS [[COPY]] - ; CHECK: $d0 = COPY [[ABS]](<4 x s16>) - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<4 x s16>) = COPY $d0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<4 x s16>) = G_ABS [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABS]](<4 x s16>) + ; CHECK-NEXT: RET_ReallyLR implicit $d0 + ; CHECK-CSSC-LABEL: name: abs_v4s16 + ; CHECK-CSSC: liveins: $d0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<4 x s16>) = COPY $d0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<4 x s16>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $d0 = COPY [[ABS]](<4 x s16>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $d0 %0:_(<4 x s16>) = COPY $d0 %1:_(<4 x s16>) = G_ABS %0 $d0 = COPY %1(<4 x s16>) @@ -60,10 +77,18 @@ ; CHECK-LABEL: name: abs_v8s16 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:_(<8 x s16>) = COPY $q0 - ; CHECK: [[ABS:%[0-9]+]]:_(<8 x s16>) = G_ABS [[COPY]] - ; CHECK: $q0 = COPY [[ABS]](<8 x s16>) - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<8 x s16>) = COPY $q0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<8 x s16>) = G_ABS [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABS]](<8 x s16>) + ; CHECK-NEXT: RET_ReallyLR implicit $q0 + ; CHECK-CSSC-LABEL: name: abs_v8s16 + ; CHECK-CSSC: liveins: $q0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<8 x s16>) = COPY $q0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<8 x s16>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $q0 = COPY [[ABS]](<8 x s16>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $q0 %0:_(<8 x s16>) = COPY $q0 %1:_(<8 x s16>) = G_ABS %0 $q0 = COPY %1(<8 x s16>) @@ -79,10 +104,18 @@ ; CHECK-LABEL: name: abs_v2s32 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0 - ; CHECK: [[ABS:%[0-9]+]]:_(<2 x s32>) = G_ABS [[COPY]] - ; CHECK: $d0 = COPY [[ABS]](<2 x s32>) - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<2 x s32>) = G_ABS [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABS]](<2 x s32>) + ; CHECK-NEXT: RET_ReallyLR implicit $d0 + ; CHECK-CSSC-LABEL: name: abs_v2s32 + ; CHECK-CSSC: liveins: $d0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<2 x s32>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $d0 = COPY [[ABS]](<2 x s32>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $d0 %0:_(<2 x s32>) = COPY $d0 %1:_(<2 x s32>) = G_ABS %0 $d0 = COPY %1(<2 x s32>) @@ -98,10 +131,18 @@ ; CHECK-LABEL: name: abs_v4s32 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0 - ; CHECK: [[ABS:%[0-9]+]]:_(<4 x s32>) = G_ABS [[COPY]] - ; CHECK: $q0 = COPY [[ABS]](<4 x s32>) - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<4 x s32>) = G_ABS [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABS]](<4 x s32>) + ; CHECK-NEXT: RET_ReallyLR implicit $q0 + ; CHECK-CSSC-LABEL: name: abs_v4s32 + ; CHECK-CSSC: liveins: $q0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<4 x s32>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $q0 = COPY [[ABS]](<4 x s32>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $q0 %0:_(<4 x s32>) = COPY $q0 %1:_(<4 x s32>) = G_ABS %0 $q0 = COPY %1(<4 x s32>) @@ -117,10 +158,18 @@ ; CHECK-LABEL: name: abs_v4s8 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:_(<8 x s8>) = COPY $d0 - ; CHECK: [[ABS:%[0-9]+]]:_(<8 x s8>) = G_ABS [[COPY]] - ; CHECK: $d0 = COPY [[ABS]](<8 x s8>) - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<8 x s8>) = COPY $d0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<8 x s8>) = G_ABS [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABS]](<8 x s8>) + ; CHECK-NEXT: RET_ReallyLR implicit $d0 + ; CHECK-CSSC-LABEL: name: abs_v4s8 + ; CHECK-CSSC: liveins: $d0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<8 x s8>) = COPY $d0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<8 x s8>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $d0 = COPY [[ABS]](<8 x s8>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $d0 %0:_(<8 x s8>) = COPY $d0 %1:_(<8 x s8>) = G_ABS %0 $d0 = COPY %1(<8 x s8>) @@ -136,10 +185,18 @@ ; CHECK-LABEL: name: abs_v16s8 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:_(<16 x s8>) = COPY $q0 - ; CHECK: [[ABS:%[0-9]+]]:_(<16 x s8>) = G_ABS [[COPY]] - ; CHECK: $q0 = COPY [[ABS]](<16 x s8>) - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<16 x s8>) = COPY $q0 + ; CHECK-NEXT: [[ABS:%[0-9]+]]:_(<16 x s8>) = G_ABS [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABS]](<16 x s8>) + ; CHECK-NEXT: RET_ReallyLR implicit $q0 + ; CHECK-CSSC-LABEL: name: abs_v16s8 + ; CHECK-CSSC: liveins: $q0 + ; CHECK-CSSC-NEXT: {{ $}} + ; CHECK-CSSC-NEXT: [[COPY:%[0-9]+]]:_(<16 x s8>) = COPY $q0 + ; CHECK-CSSC-NEXT: [[ABS:%[0-9]+]]:_(<16 x s8>) = G_ABS [[COPY]] + ; CHECK-CSSC-NEXT: $q0 = COPY [[ABS]](<16 x s8>) + ; CHECK-CSSC-NEXT: RET_ReallyLR implicit $q0 %0:_(<16 x s8>) = COPY $q0 %1:_(<16 x s8>) = G_ABS %0 $q0 = COPY %1(<16 x s8>) diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-abs.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-abs.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/select-abs.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-abs.mir @@ -13,10 +13,11 @@ ; CHECK-LABEL: name: v4s16 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 - ; CHECK: [[ABSv4i16_:%[0-9]+]]:fpr64 = ABSv4i16 [[COPY]] - ; CHECK: $d0 = COPY [[ABSv4i16_]] - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 + ; CHECK-NEXT: [[ABSv4i16_:%[0-9]+]]:fpr64 = ABSv4i16 [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABSv4i16_]] + ; CHECK-NEXT: RET_ReallyLR implicit $d0 %0:fpr(<4 x s16>) = COPY $d0 %1:fpr(<4 x s16>) = G_ABS %0 $d0 = COPY %1(<4 x s16>) @@ -34,10 +35,11 @@ ; CHECK-LABEL: name: v8s16 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 - ; CHECK: [[ABSv8i16_:%[0-9]+]]:fpr128 = ABSv8i16 [[COPY]] - ; CHECK: $q0 = COPY [[ABSv8i16_]] - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 + ; CHECK-NEXT: [[ABSv8i16_:%[0-9]+]]:fpr128 = ABSv8i16 [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABSv8i16_]] + ; CHECK-NEXT: RET_ReallyLR implicit $q0 %0:fpr(<8 x s16>) = COPY $q0 %1:fpr(<8 x s16>) = G_ABS %0 $q0 = COPY %1(<8 x s16>) @@ -55,10 +57,11 @@ ; CHECK-LABEL: name: v2s32 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 - ; CHECK: [[ABSv2i32_:%[0-9]+]]:fpr64 = ABSv2i32 [[COPY]] - ; CHECK: $d0 = COPY [[ABSv2i32_]] - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 + ; CHECK-NEXT: [[ABSv2i32_:%[0-9]+]]:fpr64 = ABSv2i32 [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABSv2i32_]] + ; CHECK-NEXT: RET_ReallyLR implicit $d0 %0:fpr(<2 x s32>) = COPY $d0 %1:fpr(<2 x s32>) = G_ABS %0 $d0 = COPY %1(<2 x s32>) @@ -76,10 +79,11 @@ ; CHECK-LABEL: name: v4s32 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 - ; CHECK: [[ABSv4i32_:%[0-9]+]]:fpr128 = ABSv4i32 [[COPY]] - ; CHECK: $q0 = COPY [[ABSv4i32_]] - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 + ; CHECK-NEXT: [[ABSv4i32_:%[0-9]+]]:fpr128 = ABSv4i32 [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABSv4i32_]] + ; CHECK-NEXT: RET_ReallyLR implicit $q0 %0:fpr(<4 x s32>) = COPY $q0 %1:fpr(<4 x s32>) = G_ABS %0 $q0 = COPY %1(<4 x s32>) @@ -97,10 +101,11 @@ ; CHECK-LABEL: name: v4s8 ; CHECK: liveins: $d0 - ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 - ; CHECK: [[ABSv8i8_:%[0-9]+]]:fpr64 = ABSv8i8 [[COPY]] - ; CHECK: $d0 = COPY [[ABSv8i8_]] - ; CHECK: RET_ReallyLR implicit $d0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr64 = COPY $d0 + ; CHECK-NEXT: [[ABSv8i8_:%[0-9]+]]:fpr64 = ABSv8i8 [[COPY]] + ; CHECK-NEXT: $d0 = COPY [[ABSv8i8_]] + ; CHECK-NEXT: RET_ReallyLR implicit $d0 %0:fpr(<8 x s8>) = COPY $d0 %1:fpr(<8 x s8>) = G_ABS %0 $d0 = COPY %1(<8 x s8>) @@ -118,10 +123,11 @@ ; CHECK-LABEL: name: v16s8 ; CHECK: liveins: $q0 - ; CHECK: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 - ; CHECK: [[ABSv16i8_:%[0-9]+]]:fpr128 = ABSv16i8 [[COPY]] - ; CHECK: $q0 = COPY [[ABSv16i8_]] - ; CHECK: RET_ReallyLR implicit $q0 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:fpr128 = COPY $q0 + ; CHECK-NEXT: [[ABSv16i8_:%[0-9]+]]:fpr128 = ABSv16i8 [[COPY]] + ; CHECK-NEXT: $q0 = COPY [[ABSv16i8_]] + ; CHECK-NEXT: RET_ReallyLR implicit $q0 %0:fpr(<16 x s8>) = COPY $q0 %1:fpr(<16 x s8>) = G_ABS %0 $q0 = COPY %1(<16 x s8>)