Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,29 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
// 32/64-bits needs support for s64/s128 to handle cases:
// s64 = EXTEND (G_IMPLICIT_DEF s32) -> s64 = G_IMPLICIT_DEF
// s128 = EXTEND (G_IMPLICIT_DEF s32/s64) -> s128 = G_IMPLICIT_DEF
getActionDefinitionsBuilder(G_IMPLICIT_DEF)
getActionDefinitionsBuilder(
{G_IMPLICIT_DEF, G_PHI, G_FREEZE, G_CONSTANT_FOLD_BARRIER})
.legalFor({p0, s1, s8, s16, s32, s64})
.legalFor(Is64Bit, {s128});
.legalFor(UseX87, {s80})
.legalFor(Is64Bit, {s128})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

G_PHI, G_IMPLICIT_DEF, and G_FREEZE (and a few others) should have identical rule sets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean grouping them under the same ActionDefinitionsBuilder so they share an identical rule set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We probably should enforce this somehow. We have an implicit notion of legal types, which we would be better off if we formalized and had the machine verifier enforce. It's certainly weaker than the DAG case, but we do need to guarantee a set of properties to ensure the legalizer can complete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I will fuse them in the legalizer, and I’ll look to see how we can enforce this in the machine verifier.

.legalFor(HasSSE2, {v16s8, v8s16, v4s32, v2s64})
.legalFor(HasAVX, {v32s8, v16s16, v8s32, v4s64})
.legalFor(HasAVX512, {v64s8, v32s16, v16s32, v8s64})
.widenScalarOrEltToNextPow2(0, /*Min=*/8)
.clampScalarOrElt(0, s8, sMaxScalar)
.moreElementsToNextPow2(0)
.clampMinNumElements(0, s8, 16)
.clampMinNumElements(0, s16, 8)
.clampMinNumElements(0, s32, 4)
.clampMinNumElements(0, s64, 2)
.clampMaxNumElements(0, s8, HasAVX512 ? 64 : (HasAVX ? 32 : 16))
.clampMaxNumElements(0, s16, HasAVX512 ? 32 : (HasAVX ? 16 : 8))
.clampMaxNumElements(0, s32, HasAVX512 ? 16 : (HasAVX ? 8 : 4))
.clampMaxNumElements(0, s64, HasAVX512 ? 8 : (HasAVX ? 4 : 2))
.clampMaxNumElements(0, p0,
Is64Bit ? s64MaxVector.getNumElements()
: s32MaxVector.getNumElements())
.scalarizeIf(scalarOrEltWiderThan(0, 64), 0);

getActionDefinitionsBuilder(G_CONSTANT)
.legalFor({p0, s8, s16, s32})
Expand Down Expand Up @@ -285,26 +305,6 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.clampScalar(1, s16, sMaxScalar)
.scalarSameSizeAs(0, 1);

// control flow
getActionDefinitionsBuilder(G_PHI)
.legalFor({s8, s16, s32, p0})
.legalFor(UseX87, {s80})
.legalFor(Is64Bit, {s64})
.legalFor(HasSSE1, {v16s8, v8s16, v4s32, v2s64})
.legalFor(HasAVX, {v32s8, v16s16, v8s32, v4s64})
.legalFor(HasAVX512, {v64s8, v32s16, v16s32, v8s64})
.clampMinNumElements(0, s8, 16)
.clampMinNumElements(0, s16, 8)
.clampMinNumElements(0, s32, 4)
.clampMinNumElements(0, s64, 2)
.clampMaxNumElements(0, s8, HasAVX512 ? 64 : (HasAVX ? 32 : 16))
.clampMaxNumElements(0, s16, HasAVX512 ? 32 : (HasAVX ? 16 : 8))
.clampMaxNumElements(0, s32, HasAVX512 ? 16 : (HasAVX ? 8 : 4))
.clampMaxNumElements(0, s64, HasAVX512 ? 8 : (HasAVX ? 4 : 2))
.widenScalarToNextPow2(0, /*Min=*/32)
.clampScalar(0, s8, sMaxScalar)
.scalarize(0);

getActionDefinitionsBuilder(G_BRCOND).legalFor({s1});

// pointer handling
Expand Down Expand Up @@ -588,11 +588,6 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.minScalar(0, LLT::scalar(32))
.libcall();

getActionDefinitionsBuilder({G_FREEZE, G_CONSTANT_FOLD_BARRIER})
.legalFor({s8, s16, s32, s64, p0})
.widenScalarToNextPow2(0, /*Min=*/8)
.clampScalar(0, s8, sMaxScalar);

getLegacyLegalizerInfo().computeTables();
verify(*STI.getInstrInfo());
}
Expand Down
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/X86/GlobalISel/legalize-g_implicit_def.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# RUN: llc -mtriple=x86_64-linux-gnu -mattr=avx2 -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s -o - | FileCheck %s --check-prefixes=CHECK,AVX2
# RUN: llc -mtriple=x86_64-linux-gnu -mattr=sse2 -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s -o - | FileCheck %s --check-prefixes=CHECK,SSE2
# RUN: llc -mtriple=x86_64-linux-gnu -mattr=avx512f -run-pass=legalizer -global-isel-abort=2 -pass-remarks-missed='gisel*' %s -o - | FileCheck %s --check-prefixes=CHECK,AVX512F


---
name: test_basic_g_implicit_def_v8i64
body: |
bb.0:
; CHECK-LABEL: name: test_basic_g_implicit_def_v8i64
; AVX512F: {{%[0-9]+}}:_(<8 x s64>) = G_IMPLICIT_DEF
; AVX2: [[DEF_AVX2:%[0-9]+]]:_(<4 x s64>) = G_IMPLICIT_DEF
; AVX2-NEXT: {{%[0-9]+}}:_(<8 x s64>) = G_CONCAT_VECTORS [[DEF_AVX2]](<4 x s64>), [[DEF_AVX2]](<4 x s64>)
; SSE2: [[DEF_SSE2:%[0-9]+]]:_(<2 x s64>) = G_IMPLICIT_DEF
; SSE2-NEXT: {{%[0-9]+}}:_(<8 x s64>) = G_CONCAT_VECTORS [[DEF_SSE2]](<2 x s64>), [[DEF_SSE2]](<2 x s64>), [[DEF_SSE2]](<2 x s64>), [[DEF_SSE2]](<2 x s64>)
%0:_(<8 x s64>) = G_IMPLICIT_DEF
RET 0, implicit %0
...

---
name: test_g_implicit_def_cample_size
body: |
bb.1:
; CHECK-LABEL: name: test_g_implicit_def_cample_size
; AVX512: {{%[0-9]+}}:_(<8 x s64>) = G_IMPLICIT_DEF
; AVX2: {{%[0-9]+}}:_(<4 x s64>) = G_IMPLICIT_DEF
; SSE2: {{%[0-9]+}}:_(<2 x s64>) = G_IMPLICIT_DEF
%0:_(<5 x s63>) = G_IMPLICIT_DEF
RET 0, implicit %0
...


14 changes: 7 additions & 7 deletions llvm/test/CodeGen/X86/GlobalISel/legalize-phi.mir
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,21 @@ body: |
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY1]](s32)
; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY $edx
; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s1) = G_TRUNC [[COPY2]](s32)
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s8) = G_ICMP intpred(sgt), [[COPY]](s32), [[C]]
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[ICMP]](s8)
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s8) = G_TRUNC [[COPY1]](s32)
; CHECK-NEXT: G_BRCOND [[TRUNC]](s1), %bb.2
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[ICMP]](s8)
; CHECK-NEXT: G_BRCOND [[TRUNC1]](s1), %bb.2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1.cond.false:
; CHECK-NEXT: successors: %bb.2(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s8) = G_TRUNC [[COPY2]](s32)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.2.cond.end:
; CHECK-NEXT: [[PHI:%[0-9]+]]:_(s8) = G_PHI [[TRUNC2]](s8), %bb.1, [[TRUNC1]](s8), %bb.0
; CHECK-NEXT: $al = COPY [[PHI]](s8)
; CHECK-NEXT: [[PHI:%[0-9]+]]:_(s1) = G_PHI [[TRUNC2]](s1), %bb.1, [[TRUNC]](s1), %bb.0
; CHECK-NEXT: [[EXT:%[0-9]+]]:_(s8) = G_ANYEXT [[PHI]](s1)
; CHECK-NEXT: $al = COPY [[EXT]](s8)
; CHECK-NEXT: RET 0, implicit $al
bb.1.entry:
successors: %bb.3(0x40000000), %bb.2(0x40000000)
Expand Down