[llvm] 6af8d36 - [AArch4][GlobalISel] Post-legalize combine s64 = G_MERGE s32, 0 -> G_ZEXT.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 26 10:58:11 PDT 2021
Author: Amara Emerson
Date: 2021-07-26T10:58:04-07:00
New Revision: 6af8d360546e01ee2e8c8c45fb5d0cf39fcda462
URL: https://github.com/llvm/llvm-project/commit/6af8d360546e01ee2e8c8c45fb5d0cf39fcda462
DIFF: https://github.com/llvm/llvm-project/commit/6af8d360546e01ee2e8c8c45fb5d0cf39fcda462.diff
LOG: [AArch4][GlobalISel] Post-legalize combine s64 = G_MERGE s32, 0 -> G_ZEXT.
These are generated as a byproduce of legalization.
Differential Revision: https://reviews.llvm.org/D106768
Added:
Modified:
llvm/lib/Target/AArch64/AArch64Combine.td
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-merge.mir
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td b/llvm/lib/Target/AArch64/AArch64Combine.td
index 6af11af8b21e..7f9b2fe81527 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -182,6 +182,13 @@ def form_truncstore : GICombineRule<
(apply [{ applyFormTruncstore(*${root}, MRI, B, Observer, ${matchinfo}); }])
>;
+def fold_merge_to_zext : GICombineRule<
+ (defs root:$d),
+ (match (wip_match_opcode G_MERGE_VALUES):$d,
+ [{ return matchFoldMergeToZext(*${d}, MRI); }]),
+ (apply [{ applyFoldMergeToZext(*${d}, MRI, B, Observer); }])
+>;
+
// Post-legalization combines which should happen at all optimization levels.
// (E.g. ones that facilitate matching for the selector) For example, matching
// pseudos.
@@ -204,6 +211,6 @@ def AArch64PostLegalizerCombinerHelper
mul_const, redundant_sext_inreg,
form_bitfield_extract, rotate_out_of_range,
icmp_to_true_false_known_bits, merge_unmerge,
- select_combines]> {
+ select_combines, fold_merge_to_zext]> {
let DisableRuleOption = "aarch64postlegalizercombiner-disable-rule";
}
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
index 3001a8f9b18e..b700c3760a58 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
@@ -23,6 +23,7 @@
#include "llvm/CodeGen/GlobalISel/Combiner.h"
#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
#include "llvm/CodeGen/GlobalISel/CombinerInfo.h"
+#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
@@ -240,6 +241,27 @@ bool applyAArch64MulConstCombine(
return true;
}
+/// Try to fold a G_MERGE_VALUES of 2 s32 sources, where the second source
+/// is a zero, into a G_ZEXT of the first.
+bool matchFoldMergeToZext(MachineInstr &MI, MachineRegisterInfo &MRI) {
+ auto &Merge = cast<GMerge>(MI);
+ LLT SrcTy = MRI.getType(Merge.getSourceReg(0));
+ if (SrcTy != LLT::scalar(32) || Merge.getNumSources() != 2)
+ return false;
+ return mi_match(Merge.getSourceReg(1), MRI, m_SpecificICst(0));
+}
+
+void applyFoldMergeToZext(MachineInstr &MI, MachineRegisterInfo &MRI,
+ MachineIRBuilder &B, GISelChangeObserver &Observer) {
+ // Mutate %d(s64) = G_MERGE_VALUES %a(s32), 0(s32)
+ // ->
+ // %d(s64) = G_ZEXT %a(s32)
+ Observer.changingInstr(MI);
+ MI.setDesc(B.getTII().get(TargetOpcode::G_ZEXT));
+ MI.RemoveOperand(2);
+ Observer.changedInstr(MI);
+}
+
#define AARCH64POSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
#include "AArch64GenPostLegalizeGICombiner.inc"
#undef AARCH64POSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-merge.mir b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-merge.mir
index 83b6d02e3a50..86dd0a5ebfd6 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-merge.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-merge.mir
@@ -68,3 +68,25 @@ body: |
RET_ReallyLR implicit $x0
...
+---
+name: merge_to_zext
+alignment: 4
+legalized: true
+liveins:
+ - { reg: '$w0' }
+body: |
+ bb.1.entry:
+ liveins: $w0
+
+ ; CHECK-LABEL: name: merge_to_zext
+ ; CHECK: %v:_(s32) = COPY $w0
+ ; CHECK: %merge:_(s64) = G_ZEXT %v(s32)
+ ; CHECK: $x0 = COPY %merge(s64)
+ ; CHECK: RET_ReallyLR implicit $x0
+ %v:_(s32) = COPY $w0
+ %zero:_(s32) = G_CONSTANT i32 0
+ %merge:_(s64) = G_MERGE_VALUES %v, %zero
+ $x0 = COPY %merge(s64)
+ RET_ReallyLR implicit $x0
+
+...
More information about the llvm-commits
mailing list