[PATCH] D72636: Cancelling out G_MERGE_VALUES/G_UNMERGE pairs sometimes needs a copy
Daniel Sanders via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 15:35:36 PST 2020
dsanders updated this revision to Diff 237799.
dsanders added a comment.
Fix the remaining small issues
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72636/new/
https://reviews.llvm.org/D72636
Files:
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
llvm/test/CodeGen/AArch64/GlobalISel/legalize-merge-values.mir
Index: llvm/test/CodeGen/AArch64/GlobalISel/legalize-merge-values.mir
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/legalize-merge-values.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/legalize-merge-values.mir
@@ -25,3 +25,40 @@
%4:_(s64) = G_ANYEXT %3
$x0 = COPY %4
...
+
+---
+name: cancel_into_nothing
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: cancel_into_nothing
+ ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
+ ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
+ ; CHECK: $w10 = COPY [[COPY]](s32)
+ ; CHECK: $w11 = COPY [[COPY1]](s32)
+ %0:_(s32) = COPY $w0
+ %1:_(s32) = COPY $w1
+ %2:_(s64) = G_MERGE_VALUES %0, %1
+ %3:_(s32), %4:_(s32) = G_UNMERGE_VALUES %2
+ $w10 = COPY %3
+ $w11 = COPY %4
+...
+
+---
+name: cancel_into_copy
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: cancel_into_copy
+ ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
+ ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
+ ; CHECK: [[COPY2:%[0-9]+]]:gpr32sp(s32) = COPY [[COPY]](s32)
+ ; CHECK: [[ADDWri:%[0-9]+]]:gpr32sp(s32) = ADDWri [[COPY2]](s32), 1, 0
+ ; CHECK: $w10 = COPY [[COPY2]](s32)
+ ; CHECK: $w11 = COPY [[COPY1]](s32)
+ %0:_(s32) = COPY $w0
+ %1:_(s32) = COPY $w1
+ %2:_(s64) = G_MERGE_VALUES %0, %1
+ %3:gpr32sp(s32), %4:_(s32) = G_UNMERGE_VALUES %2
+ %5:gpr32sp(s32) = ADDWri %3:gpr32sp(s32), 1, 0
+ $w10 = COPY %3
+ $w11 = COPY %4
+...
Index: llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -396,7 +396,15 @@
for (unsigned Idx = 0; Idx < NumDefs; ++Idx) {
Register NewDef = MergeI->getOperand(Idx + 1).getReg();
- MRI.replaceRegWith(MI.getOperand(Idx).getReg(), NewDef);
+ Register OldReg = MI.getOperand(Idx).getReg();
+ auto *OldRC = MRI.getRegClassOrNull(OldReg);
+ auto *NewRC = MRI.getRegClassOrNull(NewDef);
+ if (OldRC == NewRC)
+ MRI.replaceRegWith(OldReg, NewDef);
+ else {
+ Builder.setInstr(MI);
+ Builder.buildCopy({OldReg}, {NewDef});
+ }
UpdatedDefs.push_back(NewDef);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72636.237799.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200113/599ea8c0/attachment.bin>
More information about the llvm-commits
mailing list