Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GlobalISel] Combine (x op 0) -> x for operations with a right identi…
…ty of 0 Implement identity combines for operations like the following: ``` %a = G_SUB %b, 0 ``` This can just be replaced with %b. Over CTMark, this gives some minor size improvements at -O3. Differential Revision: https://reviews.llvm.org/D76640
- Loading branch information
Jessica Paquette
committed
Mar 30, 2020
1 parent
cf36f98
commit 63d70ea
Showing
4 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s | ||
|
||
name: right_ident_sub | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x - 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_sub | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_SUB %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_add | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x + 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_add | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_ADD %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_or | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x || 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_or | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_OR %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_xor | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x | 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_xor | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_XOR %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_shl | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x << 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_shl | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_SHL %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_ashr | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x ashr 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_ashr | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_ASHR %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: right_ident_lshr | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Fold (x lshr 0) -> x | ||
; | ||
; CHECK-LABEL: name: right_ident_lshr | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: $w0 = COPY %x(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 0 | ||
%op:_(s32) = G_LSHR %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... | ||
--- | ||
name: dont_fold_sub | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1.entry: | ||
liveins: $w0 | ||
; Not an identity, no folding. | ||
; | ||
; CHECK-LABEL: name: dont_fold_sub | ||
; CHECK: liveins: $w0 | ||
; CHECK: %x:_(s32) = COPY $w0 | ||
; CHECK: %cst:_(s32) = G_CONSTANT i32 1 | ||
; CHECK: %op:_(s32) = G_SUB %x, %cst | ||
; CHECK: $w0 = COPY %op(s32) | ||
; CHECK: RET_ReallyLR implicit $w0 | ||
%x:_(s32) = COPY $w0 | ||
%cst:_(s32) = G_CONSTANT i32 1 | ||
%op:_(s32) = G_SUB %x(s32), %cst | ||
$w0 = COPY %op(s32) | ||
RET_ReallyLR implicit $w0 | ||
... |