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 @@ -109,8 +109,8 @@ getActionDefinitionsBuilder(G_BSWAP) .legalFor({s32, s64, v4s32, v2s32, v2s64}) - .clampScalar(0, s32, s64) .widenScalarToNextPow2(0) + .clampScalar(0, s32, s64) .customIf(typeIs(0, v2s16)); // custom lower as G_REV32 + G_LSHR getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir @@ -1,27 +1,10 @@ # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py # RUN: llc -march=aarch64 -run-pass=legalizer %s -o - -verify-machineinstrs | FileCheck %s ---- | - target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" - target triple = "aarch64" - - declare i16 @llvm.bswap.i16(i16) #0 - - define i16 @bswap_s16(i16 %a) { ret i16 0 } - - define <2 x i16> @bswap_2xi16(<2 x i16> %a) { ret <2 x i16> } - - attributes #0 = { nounwind readnone speculatable willreturn } ... --- name: bswap_s16 -alignment: 4 tracksRegLiveness: true -liveins: - - { reg: '$w0' } -frameInfo: - maxAlignment: 1 -machineFunctionInfo: {} body: | bb.1: liveins: $w0 @@ -42,20 +25,10 @@ %3:_(s32) = G_ANYEXT %2(s16) $w0 = COPY %3(s32) RET_ReallyLR implicit $w0 - ... --- name: bswap_2xi16 -alignment: 4 tracksRegLiveness: true -registers: - - { id: 0, class: _ } - - { id: 1, class: _ } -liveins: - - { reg: '$s0' } -frameInfo: - maxAlignment: 1 -machineFunctionInfo: {} body: | bb.1: liveins: $s0 @@ -79,5 +52,147 @@ %1:_(<2 x s16>) = G_BSWAP %0 $s0 = COPY %1(<2 x s16>) RET_ReallyLR - ... +--- +name: bswap_s32_legal +tracksRegLiveness: true +body: | + bb.0: + liveins: $w0 + ; CHECK-LABEL: name: bswap_s32_legal + ; CHECK: liveins: $w0 + ; CHECK: %copy:_(s32) = COPY $w0 + ; CHECK: %bswap:_(s32) = G_BSWAP %copy + ; CHECK: $w0 = COPY %bswap(s32) + ; CHECK: RET_ReallyLR implicit $w0 + %copy:_(s32) = COPY $w0 + %bswap:_(s32) = G_BSWAP %copy + $w0 = COPY %bswap(s32) + RET_ReallyLR implicit $w0 +... +--- +name: bswap_s64_legal +tracksRegLiveness: true +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: bswap_s64_legal + ; CHECK: liveins: $x0 + ; CHECK: %copy:_(s64) = COPY $x0 + ; CHECK: %bswap:_(s64) = G_BSWAP %copy + ; CHECK: $x0 = COPY %bswap(s64) + ; CHECK: RET_ReallyLR implicit $x0 + %copy:_(s64) = COPY $x0 + %bswap:_(s64) = G_BSWAP %copy + $x0 = COPY %bswap(s64) + RET_ReallyLR implicit $x0 +... +--- +name: bswap_v4s32_legal +tracksRegLiveness: true +body: | + bb.0: + liveins: $q0 + ; CHECK-LABEL: name: bswap_v4s32_legal + ; CHECK: liveins: $q0 + ; CHECK: %copy:_(<4 x s32>) = COPY $q0 + ; CHECK: %bswap:_(<4 x s32>) = G_BSWAP %copy + ; CHECK: $q0 = COPY %bswap(<4 x s32>) + ; CHECK: RET_ReallyLR implicit $q0 + %copy:_(<4 x s32>) = COPY $q0 + %bswap:_(<4 x s32>) = G_BSWAP %copy + $q0 = COPY %bswap(<4 x s32>) + RET_ReallyLR implicit $q0 +... +--- +name: bswap_v2s32_legal +tracksRegLiveness: true +body: | + bb.0: + liveins: $d0 + ; CHECK-LABEL: name: bswap_v2s32_legal + ; CHECK: liveins: $d0 + ; CHECK: %copy:_(<2 x s32>) = COPY $d0 + ; CHECK: %bswap:_(<2 x s32>) = G_BSWAP %copy + ; CHECK: $d0 = COPY %bswap(<2 x s32>) + ; CHECK: RET_ReallyLR implicit $d0 + %copy:_(<2 x s32>) = COPY $d0 + %bswap:_(<2 x s32>) = G_BSWAP %copy + $d0 = COPY %bswap(<2 x s32>) + RET_ReallyLR implicit $d0 +... +--- +name: bswap_v2s64_legal +tracksRegLiveness: true +body: | + bb.0: + liveins: $q0 + ; CHECK-LABEL: name: bswap_v2s64_legal + ; CHECK: liveins: $q0 + ; CHECK: %copy:_(<2 x s64>) = COPY $q0 + ; CHECK: %bswap:_(<2 x s64>) = G_BSWAP %copy + ; CHECK: $q0 = COPY %bswap(<2 x s64>) + ; CHECK: RET_ReallyLR implicit $q0 + %copy:_(<2 x s64>) = COPY $q0 + %bswap:_(<2 x s64>) = G_BSWAP %copy + $q0 = COPY %bswap(<2 x s64>) + RET_ReallyLR implicit $q0 +... +--- +name: bswap_s88 +tracksRegLiveness: true +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: bswap_s88 + ; CHECK: liveins: $x0 + ; CHECK: [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF + ; CHECK: [[BSWAP:%[0-9]+]]:_(s64) = G_BSWAP [[DEF]] + ; CHECK: [[BSWAP1:%[0-9]+]]:_(s64) = G_BSWAP [[DEF]] + ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 40 + ; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0 + ; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 64 + ; CHECK: [[SUB:%[0-9]+]]:_(s64) = G_SUB [[C]], [[C2]] + ; CHECK: [[SUB1:%[0-9]+]]:_(s64) = G_SUB [[C2]], [[C]] + ; CHECK: [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ult), [[C]](s64), [[C2]] + ; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[ICMP]](s32) + ; CHECK: [[ICMP1:%[0-9]+]]:_(s32) = G_ICMP intpred(eq), [[C]](s64), [[C1]] + ; CHECK: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[ICMP1]](s32) + ; CHECK: [[LSHR:%[0-9]+]]:_(s64) = G_LSHR [[BSWAP1]], [[C]](s64) + ; CHECK: [[LSHR1:%[0-9]+]]:_(s64) = G_LSHR [[BSWAP]], [[C]](s64) + ; CHECK: [[SHL:%[0-9]+]]:_(s64) = G_SHL [[BSWAP1]], [[SUB1]](s64) + ; CHECK: [[OR:%[0-9]+]]:_(s64) = G_OR [[LSHR1]], [[SHL]] + ; CHECK: [[LSHR2:%[0-9]+]]:_(s64) = G_LSHR [[BSWAP1]], [[SUB]](s64) + ; CHECK: [[SELECT:%[0-9]+]]:_(s64) = G_SELECT [[TRUNC]](s1), [[OR]], [[LSHR2]] + ; CHECK: [[SELECT1:%[0-9]+]]:_(s64) = G_SELECT [[TRUNC1]](s1), [[BSWAP]], [[SELECT]] + ; CHECK: [[SELECT2:%[0-9]+]]:_(s64) = G_SELECT [[TRUNC]](s1), [[LSHR]], [[C1]] + ; CHECK: $x0 = COPY [[SELECT1]](s64) + ; CHECK: RET_ReallyLR implicit $x0 + %val:_(s88) = G_IMPLICIT_DEF + %bswap:_(s88) = G_BSWAP %val + %trunc:_(s64) = G_TRUNC %bswap + $x0 = COPY %trunc(s64) + RET_ReallyLR implicit $x0 +... +--- +name: bswap_s4 +tracksRegLiveness: true +body: | + bb.0: + liveins: $x0 + ; CHECK-LABEL: name: bswap_s4 + ; CHECK: liveins: $x0 + ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF + ; CHECK: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[DEF]] + ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 28 + ; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s64) + ; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 15 + ; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[LSHR]](s32) + ; CHECK: %ext:_(s64) = G_AND [[ANYEXT]], [[C1]] + ; CHECK: $x0 = COPY %ext(s64) + ; CHECK: RET_ReallyLR implicit $x0 + %val:_(s4) = G_IMPLICIT_DEF + %bswap:_(s4) = G_BSWAP %val + %ext:_(s64) = G_ZEXT %bswap + $x0 = COPY %ext(s64) + RET_ReallyLR implicit $x0