[llvm] 0b771c6 - [GlobalIsel][X86] Legalize G_SELECT
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 09:54:32 PDT 2023
Author: Thorsten Schütt
Date: 2023-06-08T18:54:25+02:00
New Revision: 0b771c679af29e5209c433790d812955264c3f5f
URL: https://github.com/llvm/llvm-project/commit/0b771c679af29e5209c433790d812955264c3f5f
DIFF: https://github.com/llvm/llvm-project/commit/0b771c679af29e5209c433790d812955264c3f5f.diff
LOG: [GlobalIsel][X86] Legalize G_SELECT
with bug fixes
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D152445
Added:
llvm/test/CodeGen/X86/GlobalISel/legalize-select.mir
Modified:
llvm/lib/Target/X86/X86LegalizerInfo.cpp
llvm/test/CodeGen/X86/GlobalISel/legalize-leading-zeros.mir
llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir
llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/X86LegalizerInfo.cpp
index 94250365ddbf6..e5175211a3224 100644
--- a/llvm/lib/Target/X86/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/X86LegalizerInfo.cpp
@@ -308,6 +308,14 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
(HasAVX512 && typeInSet(0, {v16s32, v8s64})(Query));
});
+ // todo: vectors and address spaces
+ getActionDefinitionsBuilder(G_SELECT)
+ .legalFor({{s8, s32}, {s16, s32}, {s32, s32}, {s64, s32},
+ {p0, s32}})
+ .widenScalarToNextPow2(0, /*Min=*/8)
+ .clampScalar(0, s8, sMaxScalar)
+ .clampScalar(1, s32, s32);
+
setLegalizerInfo32bit();
setLegalizerInfo64bit();
setLegalizerInfoSSE1();
diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-leading-zeros.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-leading-zeros.mir
index 931a31ff3a2d2..66862e7992331 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/legalize-leading-zeros.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-leading-zeros.mir
@@ -1,10 +1,5 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
-# RUN: llc -mtriple=x86_64-linux-gnu -mattr=+lzcnt -run-pass=legalizer %s -o - | FileCheck %s --check-prefixes=CHECK,X64
-# RUN: llc -mtriple=i386-linux-gnu -mattr=+lzcnt -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s 2>%t -o - | FileCheck %s --check-prefixes=CHECK,X86
-# RUN: FileCheck -check-prefix=ERR32 %s < %t
-
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %13:_(s32), %14:_(s1) = G_USUBE %8:_, %10:_, %12:_ (in function: test_ctlz35)
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %1:_(s64) = G_SELECT %6:_(s1), %9:_, %10:_ (in function: test_ctlz64)
+# RUN: llc -mtriple=x86_64-linux-gnu -mattr=+lzcnt -run-pass=legalizer %s -o - | FileCheck %s
# test count leading zeros for s16, s32, and s64
@@ -40,6 +35,15 @@ body: |
; X86-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[MV]](s64)
; X86-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
; X86-NEXT: RET 0, implicit [[COPY]](s35)
+ ; CHECK-LABEL: name: test_ctlz35
+ ; CHECK: [[DEF:%[0-9]+]]:_(s35) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[DEF]](s35)
+ ; CHECK-NEXT: [[CTLZ:%[0-9]+]]:_(s64) = G_CTLZ [[ZEXT]](s64)
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 29
+ ; CHECK-NEXT: [[SUB:%[0-9]+]]:_(s64) = G_SUB [[CTLZ]], [[C]]
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[SUB]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s35)
%0:_(s35) = IMPLICIT_DEF
%1:_(s35) = G_CTLZ %0
%2:_(s35) = COPY %1(s35)
@@ -96,6 +100,11 @@ body: |
; X86-NEXT: [[SELECT:%[0-9]+]]:_(s64) = G_SELECT [[ICMP]](s1), [[ADD]], [[CTLZ_ZERO_UNDEF]]
; X86-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[SELECT]](s64)
; X86-NEXT: RET 0, implicit [[COPY]](s64)
+ ; CHECK-LABEL: name: test_ctlz64
+ ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[CTLZ:%[0-9]+]]:_(s64) = G_CTLZ [[DEF]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[CTLZ]](s64)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s64)
%0:_(s64) = IMPLICIT_DEF
%1:_(s64) = G_CTLZ %0
%2:_(s64) = COPY %1(s64)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-select.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-select.mir
new file mode 100644
index 0000000000000..e8714d3844b53
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-select.mir
@@ -0,0 +1,108 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
+# RUN: llc -mtriple=i386-linux-gnu -run-pass=legalizer %s -o - | FileCheck %s
+
+# test select
+
+...
+---
+name: test_selectp0
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_selectp0
+ ; CHECK: [[DEF:%[0-9]+]]:_(p0) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(p0) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s1) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[DEF2]](s1)
+ ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ZEXT]](s32), [[DEF1]], [[DEF]]
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY [[SELECT]](p0)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](p0)
+ %0:_(p0) = IMPLICIT_DEF
+ %1:_(p0) = IMPLICIT_DEF
+ %2:_(s1) = IMPLICIT_DEF
+ %3:_(p0) = G_SELECT %2, %1, %0
+ %4:_(p0) = COPY %3(p0)
+ RET 0, implicit %4
+
+...
+---
+name: test_select64
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_select64
+ ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(s64) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s1) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF1]](s64)
+ ; CHECK-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF]](s64)
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[DEF2]](s1)
+ ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ZEXT]](s32), [[UV]], [[UV2]]
+ ; CHECK-NEXT: [[SELECT1:%[0-9]+]]:_(s32) = G_SELECT [[ZEXT]](s32), [[UV1]], [[UV3]]
+ ; CHECK-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[SELECT]](s32), [[SELECT1]](s32)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[MV]](s64)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s64)
+ %0:_(s64) = IMPLICIT_DEF
+ %1:_(s64) = IMPLICIT_DEF
+ %2:_(s1) = IMPLICIT_DEF
+ %3:_(s64) = G_SELECT %2, %1, %0
+ %4:_(s64) = COPY %3(s64)
+ RET 0, implicit %4
+
+...
+---
+name: test_select32
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_select32
+ ; CHECK: [[DEF:%[0-9]+]]:_(s32) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(s32) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s1) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[DEF2]](s1)
+ ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(s32) = G_SELECT [[ZEXT]](s32), [[DEF1]], [[DEF]]
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY [[SELECT]](s32)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s32)
+ %0:_(s32) = IMPLICIT_DEF
+ %1:_(s32) = IMPLICIT_DEF
+ %2:_(s1) = IMPLICIT_DEF
+ %3:_(s32) = G_SELECT %2, %1, %0
+ %4:_(s32) = COPY %3(s32)
+ RET 0, implicit %4
+
+...
+---
+name: test_select16
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_select16
+ ; CHECK: [[DEF:%[0-9]+]]:_(s16) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(s16) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s1) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[DEF2]](s1)
+ ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(s16) = G_SELECT [[ZEXT]](s32), [[DEF1]], [[DEF]]
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY [[SELECT]](s16)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s16)
+ %0:_(s16) = IMPLICIT_DEF
+ %1:_(s16) = IMPLICIT_DEF
+ %2:_(s1) = IMPLICIT_DEF
+ %3:_(s16) = G_SELECT %2, %1, %0
+ %4:_(s16) = COPY %3(s16)
+ RET 0, implicit %4
+
+...
+---
+name: test_select8
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_select8
+ ; CHECK: [[DEF:%[0-9]+]]:_(s8) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF1:%[0-9]+]]:_(s8) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[DEF2:%[0-9]+]]:_(s1) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[DEF2]](s1)
+ ; CHECK-NEXT: [[SELECT:%[0-9]+]]:_(s8) = G_SELECT [[ZEXT]](s32), [[DEF1]], [[DEF]]
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s8) = COPY [[SELECT]](s8)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s8)
+ %0:_(s8) = IMPLICIT_DEF
+ %1:_(s8) = IMPLICIT_DEF
+ %2:_(s1) = IMPLICIT_DEF
+ %3:_(s8) = G_SELECT %2, %1, %0
+ %4:_(s8) = COPY %3(s8)
+ RET 0, implicit %4
diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir
index b8e972c5e6492..12dfe0ccff953 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros-undef.mir
@@ -1,10 +1,5 @@
# 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 --check-prefixes=CHECK,X64
-# RUN: llc -mtriple=i386-linux-gnu -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s 2>%t -o - | FileCheck %s --check-prefixes=CHECK,X86
-# RUN: FileCheck -check-prefix=ERR32 %s < %t
-
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %4:_(s64) = G_SELECT %8:_(s1), %11:_, %12:_ (in function: test_cttz35)
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %1:_(s64) = G_SELECT %6:_(s1), %9:_, %10:_ (in function: test_cttz64)
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=legalizer %s -o - | FileCheck %s
# test count leading zeros for s16, s32, and s64
@@ -39,6 +34,13 @@ body: |
; X86-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[SELECT]](s64)
; X86-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
; X86-NEXT: RET 0, implicit [[COPY]](s35)
+ ; CHECK-LABEL: name: test_cttz35
+ ; CHECK: [[DEF:%[0-9]+]]:_(s35) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[DEF]](s35)
+ ; CHECK-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s64) = G_CTTZ_ZERO_UNDEF [[ANYEXT]](s64)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[CTTZ_ZERO_UNDEF]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s35)
%0:_(s35) = IMPLICIT_DEF
%1:_(s35) = G_CTTZ_ZERO_UNDEF %0
%2:_(s35) = COPY %1(s35)
@@ -93,6 +95,11 @@ body: |
; X86-NEXT: [[SELECT:%[0-9]+]]:_(s64) = G_SELECT [[ICMP]](s1), [[ADD]], [[CTTZ_ZERO_UNDEF1]]
; X86-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[SELECT]](s64)
; X86-NEXT: RET 0, implicit [[COPY]](s64)
+ ; CHECK-LABEL: name: test_cttz64
+ ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s64) = G_CTTZ_ZERO_UNDEF [[DEF]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[CTTZ_ZERO_UNDEF]](s64)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s64)
%0:_(s64) = IMPLICIT_DEF
%1:_(s64) = G_CTTZ_ZERO_UNDEF %0
%2:_(s64) = COPY %1(s64)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir b/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir
index 7ee2b3644928c..5bb02e19783ff 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir
+++ b/llvm/test/CodeGen/X86/GlobalISel/legalize-trailing-zeros.mir
@@ -1,10 +1,5 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
-# RUN: llc -mtriple=x86_64-linux-gnu -mattr=+bmi -run-pass=legalizer %s -o - | FileCheck %s --check-prefixes=CHECK,X64
-# RUN: llc -mtriple=i386-linux-gnu -mattr=+bmi -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s 2>%t -o - | FileCheck %s --check-prefixes=CHECK,X86
-# RUN: FileCheck -check-prefix=ERR32 %s < %t
-
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %6:_(s64) = G_SELECT %10:_(s1), %13:_, %14:_ (in function: test_cttz35)
-# ERR32: remark: <unknown>:0:0: unable to legalize instruction: %1:_(s64) = G_SELECT %6:_(s1), %9:_, %10:_ (in function: test_cttz64)
+# RUN: llc -mtriple=x86_64-linux-gnu -mattr=+bmi -run-pass=legalizer %s -o - | FileCheck %s
# test count leading zeros for s16, s32, and s64
@@ -43,6 +38,15 @@ body: |
; X86-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[SELECT]](s64)
; X86-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
; X86-NEXT: RET 0, implicit [[COPY]](s35)
+ ; CHECK-LABEL: name: test_cttz35
+ ; CHECK: [[DEF:%[0-9]+]]:_(s35) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[DEF]](s35)
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 34359738368
+ ; CHECK-NEXT: [[OR:%[0-9]+]]:_(s64) = G_OR [[ANYEXT]], [[C]]
+ ; CHECK-NEXT: [[CTTZ_ZERO_UNDEF:%[0-9]+]]:_(s64) = G_CTTZ_ZERO_UNDEF [[OR]](s64)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s35) = G_TRUNC [[CTTZ_ZERO_UNDEF]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s35) = COPY [[TRUNC]](s35)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s35)
%0:_(s35) = IMPLICIT_DEF
%1:_(s35) = G_CTTZ %0
%2:_(s35) = COPY %1(s35)
@@ -99,6 +103,11 @@ body: |
; X86-NEXT: [[SELECT:%[0-9]+]]:_(s64) = G_SELECT [[ICMP]](s1), [[ADD]], [[CTTZ_ZERO_UNDEF]]
; X86-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[SELECT]](s64)
; X86-NEXT: RET 0, implicit [[COPY]](s64)
+ ; CHECK-LABEL: name: test_cttz64
+ ; CHECK: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF
+ ; CHECK-NEXT: [[CTTZ:%[0-9]+]]:_(s64) = G_CTTZ [[DEF]](s64)
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[CTTZ]](s64)
+ ; CHECK-NEXT: RET 0, implicit [[COPY]](s64)
%0:_(s64) = IMPLICIT_DEF
%1:_(s64) = G_CTTZ %0
%2:_(s64) = COPY %1(s64)
More information about the llvm-commits
mailing list