[PATCH] D109264: [GlobalISel] Add G_ROTL and G_ROTR to right_identity_zero

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 3 18:04:50 PDT 2021


paquette created this revision.
paquette added reviewers: aemerson, arsenm, jroelofs.
Herald added subscribers: steven.zhang, rovka.
paquette requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

Similar to `DAGCombiner::visitRotate`.

  rotr x, 0 -> x
  rotl x, 0 -> x

This makes rotl_bitwidth_cst in postlegalizercombiner-rotate.mir reduce down to a COPY. Modify the checkline to make sure that only rotate_out_of_range runs there.


https://reviews.llvm.org/D109264

Files:
  llvm/include/llvm/Target/GlobalISel/Combine.td
  llvm/test/CodeGen/AArch64/GlobalISel/postlegalizercombiner-rotate.mir
  llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir


Index: llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir
@@ -325,3 +325,39 @@
     %op:_(p0) = G_PTR_ADD %x(p0), %cst
     $x0 = COPY %op(p0)
     RET_ReallyLR implicit $x0
+...
+---
+name:            right_identity_rotl
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    liveins: $w0, $w1
+    ; CHECK-LABEL: name: right_identity_rotl
+    ; CHECK: liveins: $w0, $w1
+    ; CHECK: %copy:_(s32) = COPY $w0
+    ; CHECK: $w0 = COPY %copy(s32)
+    ; CHECK: RET_ReallyLR implicit $w0
+    %copy:_(s32) = COPY $w0
+    %zero:_(s32) = G_CONSTANT i32 0
+    %rot:_(s32) = G_ROTL %copy(s32), %zero(s32)
+    $w0 = COPY %rot(s32)
+    RET_ReallyLR implicit $w0
+...
+...
+---
+name:            right_identity_rotr
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    liveins: $w0, $w1
+    ; CHECK-LABEL: name: right_identity_rotr
+    ; CHECK: liveins: $w0, $w1
+    ; CHECK: %copy:_(s32) = COPY $w0
+    ; CHECK: $w0 = COPY %copy(s32)
+    ; CHECK: RET_ReallyLR implicit $w0
+    %copy:_(s32) = COPY $w0
+    %zero:_(s32) = G_CONSTANT i32 0
+    %rot:_(s32) = G_ROTR %copy(s32), %zero(s32)
+    $w0 = COPY %rot(s32)
+    RET_ReallyLR implicit $w0
+...
Index: llvm/test/CodeGen/AArch64/GlobalISel/postlegalizercombiner-rotate.mir
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/postlegalizercombiner-rotate.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/postlegalizercombiner-rotate.mir
@@ -1,5 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
-# RUN: llc -mtriple aarch64 -run-pass=aarch64-postlegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s
+# RUN: llc -mtriple aarch64 -run-pass=aarch64-postlegalizer-combiner --aarch64postlegalizercombinerhelper-only-enable-rule="rotate_out_of_range" -verify-machineinstrs %s -o - | FileCheck %s
+# REQUIRES: asserts
 
 # Check that we simplify the constant rotate amount to be in range.
 ---
Index: llvm/include/llvm/Target/GlobalISel/Combine.td
===================================================================
--- llvm/include/llvm/Target/GlobalISel/Combine.td
+++ llvm/include/llvm/Target/GlobalISel/Combine.td
@@ -281,7 +281,7 @@
 def right_identity_zero: GICombineRule<
   (defs root:$root),
   (match (wip_match_opcode G_SUB, G_ADD, G_OR, G_XOR, G_SHL, G_ASHR, G_LSHR,
-                           G_PTR_ADD):$root,
+                           G_PTR_ADD, G_ROTL, G_ROTR):$root,
     [{ return Helper.matchConstantOp(${root}->getOperand(2), 0); }]),
   (apply [{ return Helper.replaceSingleDefInstWithOperand(*${root}, 1); }])
 >;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109264.370686.patch
Type: text/x-patch
Size: 2853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210904/80b7b36f/attachment.bin>


More information about the llvm-commits mailing list