diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td b/llvm/lib/Target/AArch64/AArch64Combine.td --- a/llvm/lib/Target/AArch64/AArch64Combine.td +++ b/llvm/lib/Target/AArch64/AArch64Combine.td @@ -145,6 +145,6 @@ hoist_logic_op_with_same_opcode_hands, redundant_and, xor_of_and_with_same_reg, extractvecelt_pairwise_add, redundant_or, - mul_const]> { + mul_const, redundant_sext_inreg]> { let DisableRuleOption = "aarch64postlegalizercombiner-disable-rule"; } diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/combine-sext-trunc-sextload.mir b/llvm/test/CodeGen/AArch64/GlobalISel/combine-sext-trunc-sextload.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/combine-sext-trunc-sextload.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/combine-sext-trunc-sextload.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 + --- name: test_combine_sext_trunc_of_sextload legalized: true @@ -49,8 +50,7 @@ ; CHECK: liveins: $x0 ; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 ; CHECK: [[SEXTLOAD:%[0-9]+]]:_(s32) = G_SEXTLOAD [[COPY]](p0) :: (load 2) - ; CHECK: [[SEXT_INREG:%[0-9]+]]:_(s32) = G_SEXT_INREG [[SEXTLOAD]], 24 - ; CHECK: $w0 = COPY [[SEXT_INREG]](s32) + ; CHECK: $w0 = COPY [[SEXTLOAD]](s32) %0:_(p0) = COPY $x0 %1:_(s32) = G_SEXTLOAD %0:_(p0) :: (load 2) %2:_(s32) = COPY %1:_(s32) diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-redundant-sextinreg.mir b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-redundant-sextinreg.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-redundant-sextinreg.mir @@ -0,0 +1,83 @@ +# 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 + +... +--- +name: sextload +legalized: true +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $x0 + + ; CHECK-LABEL: name: sextload + ; CHECK: liveins: $x0 + ; CHECK: %x0:_(p0) = COPY $x0 + ; CHECK: %sextload:_(s32) = G_SEXTLOAD %x0(p0) :: (load 2) + ; CHECK: $w0 = COPY %sextload(s32) + %x0:_(p0) = COPY $x0 + %sextload:_(s32) = G_SEXTLOAD %x0:_(p0) :: (load 2) + %sext_inreg:_(s32) = G_SEXT_INREG %sextload:_(s32), 24 + $w0 = COPY %sext_inreg(s32) +... +--- +name: assert_sext +legalized: true +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $w0 + ; The G_ASSERT_SEXT says we already sign extended from 24 bits, so the + ; G_SEXT_INREG is not necessary. + + ; CHECK-LABEL: name: assert_sext + ; CHECK: liveins: $w0 + ; CHECK: %w0:_(s32) = COPY $w0 + ; CHECK: %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 24 + ; CHECK: $w0 = COPY %assert_sext(s32) + %w0:_(s32) = COPY $w0 + %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 24 + %sext_inreg:_(s32) = G_SEXT_INREG %assert_sext:_(s32), 24 + $w0 = COPY %sext_inreg(s32) +... +--- +name: assert_sext_greater_width +legalized: true +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $w0 + ; The G_ASSERT_SEXT is from a wider width than the G_SEXT_INREG, so we + ; can't eliminate it. + + ; CHECK-LABEL: name: assert_sext_greater_width + ; CHECK: liveins: $w0 + ; CHECK: %w0:_(s32) = COPY $w0 + ; CHECK: %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 24 + ; CHECK: %sext_inreg:_(s32) = G_SEXT_INREG %assert_sext, 12 + ; CHECK: $w0 = COPY %sext_inreg(s32) + %w0:_(s32) = COPY $w0 + %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 24 + %sext_inreg:_(s32) = G_SEXT_INREG %assert_sext:_(s32), 12 + $w0 = COPY %sext_inreg(s32) +... +--- +name: assert_sext_smaller_width +legalized: true +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $w0 + ; The G_ASSERT_SEXT is from a smaller width, so the G_SEXT_INREG is not + ; necessary. + + ; CHECK-LABEL: name: assert_sext_smaller_width + ; CHECK: liveins: $w0 + ; CHECK: %w0:_(s32) = COPY $w0 + ; CHECK: %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 8 + ; CHECK: $w0 = COPY %assert_sext(s32) + %w0:_(s32) = COPY $w0 + %assert_sext:_(s32) = G_ASSERT_SEXT %w0, 8 + %sext_inreg:_(s32) = G_SEXT_INREG %assert_sext:_(s32), 12 + $w0 = COPY %sext_inreg(s32) +...