[PATCH] D76523: [GlobalISel] Combine G_SELECTs of the form (cond ? x : x) into x

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 20 14:07:13 PDT 2020


paquette created this revision.
paquette added reviewers: aemerson, arsenm, dsanders.
Herald added subscribers: danielkiss, volkan, hiraditya, kristof.beyls, rovka, wdng.
paquette marked an inline comment as done.
paquette added inline comments.


================
Comment at: llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-select.mir:4-5
+
+...
+---
+name:            self
----------------
also I found out that apparently update_mir_test_checks doesn't like it when this isn't here which is weird. It will skip the function entirely.


When we find something like this:

  %a:_(s32) = G_SOMETHING ...
  ...
  %select:_(s32) = G_SELECT %cond(s1), %a, %a

We can remove the select and just replace it entirely with `%a` because it's always going to result in `%a`.

Same if we have

  %select:_(s32) = G_SELECT %cond(s1), %a, %b

where we can deduce that `%a == %b`.

This implements the following cases:

- `%select:_(s32) = G_SELECT %cond(s1), %a, %a` -> `%a`
- `%select:_(s32) = G_SELECT %cond(s1), %a, %some_copy_from_a` -> `%a`
- `%select:_(s32) = G_SELECT %cond(s1), %a, %b` -> `%a` when `%a` and `%b` are defined by identical instructions

This gives a few minor code size improvements on CTMark at -O3 for AArch64.


https://reviews.llvm.org/D76523

Files:
  llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
  llvm/include/llvm/Target/GlobalISel/Combine.td
  llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-select.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76523.251748.patch
Type: text/x-patch
Size: 7396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200320/2e7a0f84/attachment.bin>


More information about the llvm-commits mailing list