diff options
| author | Thorsten Schütt <schuett@gmail.com> | 2023-05-16 15:45:30 +0200 |
|---|---|---|
| committer | Thorsten Schütt <schuett@gmail.com> | 2023-05-16 16:02:58 +0200 |
| commit | 5cafecf9f952818400fa32645695e79838f1bc2c (patch) | |
| tree | 6581d9068adad82831c4135203014c29738b9638 | |
| parent | 1b1f1b9079e2f01f963c6c7cd766d67029ba87cb (diff) | |
| download | llvm-5cafecf9f952818400fa32645695e79838f1bc2c.tar.gz | |
[GlobalIsel][X86] Legalize G_BSWAP
remark: unable to legalize instruction: %95:_(s16) = G_BSWAP %94:_ (in function: _ZNK4llvm13DataExtractor6getU16EPyPtj) [-Rpass-missed=gisel-legalize]
check plan: ninja check-llvm-codegen-x86
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D150667
| -rw-r--r-- | llvm/lib/Target/X86/X86LegalizerInfo.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir | 113 |
2 files changed, 119 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/X86LegalizerInfo.cpp index dbe939709ff3..da24eb0f7971 100644 --- a/llvm/lib/Target/X86/X86LegalizerInfo.cpp +++ b/llvm/lib/Target/X86/X86LegalizerInfo.cpp @@ -286,6 +286,12 @@ void X86LegalizerInfo::setLegalizerInfo64bit() { LegacyLegalizeActions::Legal); LegacyInfo.setAction({G_MERGE_VALUES, 1, s128}, LegacyLegalizeActions::Legal); LegacyInfo.setAction({G_UNMERGE_VALUES, s128}, LegacyLegalizeActions::Legal); + + getActionDefinitionsBuilder({G_BSWAP}) + .legalFor({s32, s64}) + .widenScalarToNextPow2(1, /*Min=*/32) + .clampScalar(0, s32, s64); + } void X86LegalizerInfo::setLegalizerInfoSSE1() { diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir new file mode 100644 index 000000000000..f9e5a18fc315 --- /dev/null +++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-bswap.mir @@ -0,0 +1,113 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2 +# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=legalizer %s -o - | FileCheck %s + +# test BSWAP s32 and s64 + +--- +name: test_bswap_s96 +alignment: 16 +legalized: false +regBankSelected: false +registers: + - { id: 0, class: _, preferred-register: '' } + - { id: 1, class: _, preferred-register: '' } +liveins: +fixedStack: +stack: +constants: +body: | + bb.1: + ; CHECK-LABEL: name: test_bswap_s96 + ; CHECK: [[DEF:%[0-9]+]]:_(s96) = IMPLICIT_DEF + ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[DEF]](s96) + ; CHECK-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[ANYEXT]] + ; CHECK-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 -64 + ; CHECK-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s8) + ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s96) = G_TRUNC [[LSHR]](s32) + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s96) = COPY [[TRUNC]](s96) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s96) + %0:_(s96) = IMPLICIT_DEF + %1:_(s96) = G_BSWAP %0 + %2:_(s96) = COPY %1(s96) + RET 0, implicit %2 + +... +--- +name: test_bswaps64 +alignment: 16 +legalized: false +regBankSelected: false +registers: + - { id: 0, class: _, preferred-register: '' } + - { id: 1, class: _, preferred-register: '' } +liveins: +fixedStack: +stack: +constants: +body: | + bb.1: + ; CHECK-LABEL: name: test_bswaps64 + ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF + ; CHECK-NEXT: [[BSWAP:%[0-9]+]]:_(s64) = G_BSWAP [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[BSWAP]](s64) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s64) + %0:_(s64) = IMPLICIT_DEF + %1:_(s64) = G_BSWAP %0 + %2:_(s64) = COPY %1(s64) + RET 0, implicit %2 + +... +--- +name: test_bswap_s32 +alignment: 16 +legalized: false +regBankSelected: false +registers: + - { id: 0, class: _, preferred-register: '' } + - { id: 1, class: _, preferred-register: '' } +liveins: +fixedStack: +stack: +constants: +body: | + bb.1: + ; CHECK-LABEL: name: test_bswap_s32 + ; CHECK: [[DEF:%[0-9]+]]:_(s32) = IMPLICIT_DEF + ; CHECK-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[DEF]] + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY [[BSWAP]](s32) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s32) + %0:_(s32) = IMPLICIT_DEF + %1:_(s32) = G_BSWAP %0 + %2:_(s32) = COPY %1(s32) + RET 0, implicit %2 + +... +--- +name: test_bswap_s16 +alignment: 16 +legalized: false +regBankSelected: false +registers: + - { id: 0, class: _, preferred-register: '' } + - { id: 1, class: _, preferred-register: '' } +liveins: +fixedStack: +stack: +constants: +body: | + bb.1: + ; CHECK-LABEL: name: test_bswap_s16 + ; CHECK: [[DEF:%[0-9]+]]:_(s16) = IMPLICIT_DEF + ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[DEF]](s16) + ; CHECK-NEXT: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[ANYEXT]] + ; CHECK-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 16 + ; CHECK-NEXT: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s8) + ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[LSHR]](s32) + ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY [[TRUNC]](s16) + ; CHECK-NEXT: RET 0, implicit [[COPY]](s16) + %0:_(s16) = IMPLICIT_DEF + %1:_(s16) = G_BSWAP %0 + %2:_(s16) = COPY %1(s16) + RET 0, implicit %2 + +... |
