Skip to content

[GlobalISel] Improve combines for extend operation by taking hint ins… #74125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,9 @@ bool CombinerHelper::matchCombineAnyExtTrunc(MachineInstr &MI, Register &Reg) {
assert(MI.getOpcode() == TargetOpcode::G_ANYEXT && "Expected a G_ANYEXT");
Register DstReg = MI.getOperand(0).getReg();
Register SrcReg = MI.getOperand(1).getReg();
Register OriginalSrcReg = getSrcRegIgnoringCopies(SrcReg, MRI);
if (OriginalSrcReg.isValid())
SrcReg = OriginalSrcReg;
LLT DstTy = MRI.getType(DstReg);
return mi_match(SrcReg, MRI,
m_GTrunc(m_all_of(m_Reg(Reg), m_SpecificType(DstTy))));
Expand All @@ -2400,6 +2403,9 @@ bool CombinerHelper::matchCombineExtOfExt(
MI.getOpcode() == TargetOpcode::G_ZEXT) &&
"Expected a G_[ASZ]EXT");
Register SrcReg = MI.getOperand(1).getReg();
Register OriginalSrcReg = getSrcRegIgnoringCopies(SrcReg, MRI);
if (OriginalSrcReg.isValid())
SrcReg = OriginalSrcReg;
MachineInstr *SrcMI = MRI.getVRegDef(SrcReg);
// Match exts with the same opcode, anyext([sz]ext) and sext(zext).
unsigned Opc = MI.getOpcode();
Expand Down
118 changes: 118 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/combine-ext.mir
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ body: |
$x1 = COPY %2(s64)
...
---
name: test_combine_anyext_trunc_with_hint
body: |
bb.1:
liveins: $x0
; CHECK-LABEL: name: test_combine_anyext_trunc_with_hint
; CHECK: liveins: $x0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
; CHECK-NEXT: $x1 = COPY [[COPY]](s64)
%0:_(s64) = COPY $x0
%1:_(s32) = G_TRUNC %0(s64)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_ANYEXT %2(s32)
$x1 = COPY %3(s64)
...
---
name: test_combine_anyext_trunc_vec
body: |
bb.1:
Expand Down Expand Up @@ -47,6 +63,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_anyext_anyext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_anyext_anyext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[ANYEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_ANYEXT %0(s16)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_ANYEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_anyext_anyext_vec
body: |
bb.1:
Expand Down Expand Up @@ -79,6 +112,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_anyext_sext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_anyext_sext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[SEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_SEXT %0(s16)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_ANYEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_anyext_sext_vec
body: |
bb.1:
Expand Down Expand Up @@ -111,6 +161,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_anyext_zext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_anyext_zext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[ZEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_ZEXT %0(s16)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_ANYEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_anyext_zext_vec
body: |
bb.1:
Expand Down Expand Up @@ -143,6 +210,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_sext_sext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_sext_sext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[SEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_SEXT %0(s16)
%2:_(s32) = G_ASSERT_SEXT %1(s32), 11
%3:_(s64) = G_SEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_sext_sext_vec
body: |
bb.1:
Expand Down Expand Up @@ -175,6 +259,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_sext_zext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_sext_zext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[ZEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_ZEXT %0(s16)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_SEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_sext_zext_vec
body: |
bb.1:
Expand Down Expand Up @@ -207,6 +308,23 @@ body: |
$x0 = COPY %2(s64)
...
---
name: test_combine_zext_zext_with_hint
body: |
bb.1:
liveins: $h0
; CHECK-LABEL: name: test_combine_zext_zext_with_hint
; CHECK: liveins: $h0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s16) = COPY $h0
; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[COPY]](s16)
; CHECK-NEXT: $x0 = COPY [[ZEXT]](s64)
%0:_(s16) = COPY $h0
%1:_(s32) = G_ZEXT %0(s16)
%2:_(s32) = G_ASSERT_ZEXT %1(s32), 11
%3:_(s64) = G_ZEXT %2(s32)
$x0 = COPY %3(s64)
...
---
name: test_combine_zext_zext_vec
body: |
bb.1:
Expand Down