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); }]) >; 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/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 +...