diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td @@ -2392,6 +2392,11 @@ (SBFMXri GPR64:$Rn, imm0_63:$imm, 63)>; } +let AddedComplexity = 21 in { +def : Pat<(i64 (sext (i32 (sra (i32 (shl GPR32:$Rn, (i64 imm0_31:$imm))), (i64 imm0_31:$imm))))), + (SBFMXri (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GPR32:$Rn, sub_32), 0, (i64 (i32shift_b imm0_31:$imm)))>; +} + def : InstAlias<"asr $dst, $src, $shift", (SBFMWri GPR32:$dst, GPR32:$src, imm0_31:$shift, 31)>; def : InstAlias<"asr $dst, $src, $shift", diff --git a/llvm/test/CodeGen/AArch64/aarch64-combine-bit-operations.ll b/llvm/test/CodeGen/AArch64/aarch64-combine-bit-operations.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64-combine-bit-operations.ll @@ -0,0 +1,15 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=aarch64-unknown-linux-gnu -o - %s | FileCheck %s + +define i64 @sext_ashr_shl(i32 %x) { +; CHECK-LABEL: sext_ashr_shl: +; CHECK: // %bb.0: // %entry +; CHECK-NEXT: lsl w8, w0, #23 +; CHECK-NEXT: sbfx x0, x8, #23, #9 +; CHECK-NEXT: ret +entry: + %bf.cast3 = shl i32 %x, 23 + %bf.cast = ashr exact i32 %bf.cast3, 23 + %conv = sext i32 %bf.cast to i64 + ret i64 %conv +}