Skip to content

Commit 510123e

Browse files
committed
[GlobalISel] Adding G_AND identity combine
Combine G_AND(X, -1) to X.
1 parent 04f5198 commit 510123e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ def right_identity_one_int: GICombineRule<
566566
(apply (GIReplaceReg $dst, $x))
567567
>;
568568

569+
def right_identity_neg_one_int: GICombineRule<
570+
(defs root:$dst),
571+
(match (G_AND $dst, $x, -1)),
572+
(apply (GIReplaceReg $dst, $x))
573+
>;
574+
569575
def right_identity_one_fp: GICombineRule<
570576
(defs root:$dst),
571577
(match (G_FMUL $dst, $x, $y):$root,
@@ -2003,7 +2009,8 @@ def identity_combines : GICombineGroup<[select_same_val, right_identity_zero,
20032009
trunc_lshr_buildvector_fold,
20042010
bitcast_bitcast_fold, fptrunc_fpext_fold,
20052011
right_identity_neg_zero_fp,
2006-
right_identity_neg_one_fp]>;
2012+
right_identity_neg_one_fp,
2013+
right_identity_neg_one_int]>;
20072014

20082015
def const_combines : GICombineGroup<[constant_fold_fp_ops, const_ptradd_to_i2p,
20092016
overlapping_and, mulo_by_2, mulo_by_0,

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ body: |
165165
166166
...
167167

168+
---
169+
name: right_ident_and
170+
tracksRegLiveness: true
171+
body: |
172+
bb.1.entry:
173+
liveins: $w0
174+
; Fold (x & -1) -> x
175+
; CHECK-LABEL: name: right_ident_and
176+
; CHECK: liveins: $w0
177+
; CHECK-NEXT: {{ $}}
178+
; CHECK-NEXT: %x:_(s32) = COPY $w0
179+
; CHECK-NEXT: $w0 = COPY %x(s32)
180+
; CHECK-NEXT: RET_ReallyLR implicit $w0
181+
%x:_(s32) = COPY $w0
182+
%cst:_(s32) = G_CONSTANT i32 -1
183+
%op:_(s32) = G_AND %x(s32), %cst
184+
$w0 = COPY %op(s32)
185+
RET_ReallyLR implicit $w0
186+
187+
...
168188
---
169189
name: right_ident_or
170190
tracksRegLiveness: true

0 commit comments

Comments
 (0)