diff options
| author | Juergen Ributzka <juergen@apple.com> | 2014-09-18 05:40:41 +0000 |
|---|---|---|
| committer | Juergen Ributzka <juergen@apple.com> | 2014-09-18 05:40:41 +0000 |
| commit | 99b7758ba072e13cebc54ecb043f9c79315f0241 (patch) | |
| tree | 623d95a873b2c271044d6023ce017ad69b0f8c6b /llvm | |
| parent | f82886e5020c2cda518902d665cd87ddb2c40e59 (diff) | |
| download | bcm5719-llvm-99b7758ba072e13cebc54ecb043f9c79315f0241.tar.gz bcm5719-llvm-99b7758ba072e13cebc54ecb043f9c79315f0241.zip | |
[FastISel][AArch64] Fold 'AND' instruction during the address computation.
The 'AND' instruction could be used to mask out the lower 32 bits of a register.
If this is done inside an address computation we might be able to fold the
instruction into the memory instruction itself.
and x1, x1, #0xffffffff ---> ldrb x0, [x0, w1, uxtw]
ldrb x0, [x0, x1]
llvm-svn: 218030
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Target/AArch64/AArch64FastISel.cpp | 54 | ||||
| -rw-r--r-- | llvm/test/CodeGen/AArch64/fast-isel-addressing-modes.ll | 47 |
2 files changed, 99 insertions, 2 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64FastISel.cpp b/llvm/lib/Target/AArch64/AArch64FastISel.cpp index d25956c7bc4..0e9ef990962 100644 --- a/llvm/lib/Target/AArch64/AArch64FastISel.cpp +++ b/llvm/lib/Target/AArch64/AArch64FastISel.cpp @@ -596,6 +596,29 @@ bool AArch64FastISel::computeAddress(const Value *Obj, Address &Addr, Type *Ty) if (SE->getOperand(0)->getType()->isIntegerTy(32)) Addr.setExtendType(AArch64_AM::SXTW); + if (const auto *AI = dyn_cast<BinaryOperator>(U)) + if (AI->getOpcode() == Instruction::And) { + const Value *LHS = AI->getOperand(0); + const Value *RHS = AI->getOperand(1); + + if (const auto *C = dyn_cast<ConstantInt>(LHS)) + if (C->getValue() == 0xffffffff) + std::swap(LHS, RHS); + + if (const auto *C = cast<ConstantInt>(RHS)) + if (C->getValue() == 0xffffffff) { + Addr.setExtendType(AArch64_AM::UXTW); + unsigned Reg = getRegForValue(LHS); + if (!Reg) + return false; + bool RegIsKill = hasTrivialKill(LHS); + Reg = fastEmitInst_extractsubreg(MVT::i32, Reg, RegIsKill, + AArch64::sub_32); + Addr.setOffsetReg(Reg); + return true; + } + } + unsigned Reg = getRegForValue(U->getOperand(0)); if (!Reg) return false; @@ -660,6 +683,37 @@ bool AArch64FastISel::computeAddress(const Value *Obj, Address &Addr, Type *Ty) Addr.setOffsetReg(Reg); return true; } + case Instruction::And: { + if (Addr.getOffsetReg()) + break; + + if (DL.getTypeSizeInBits(Ty) != 8) + break; + + const Value *LHS = U->getOperand(0); + const Value *RHS = U->getOperand(1); + + if (const auto *C = dyn_cast<ConstantInt>(LHS)) + if (C->getValue() == 0xffffffff) + std::swap(LHS, RHS); + + if (const auto *C = cast<ConstantInt>(RHS)) + if (C->getValue() == 0xffffffff) { + Addr.setShift(0); + Addr.setExtendType(AArch64_AM::LSL); + Addr.setExtendType(AArch64_AM::UXTW); + + unsigned Reg = getRegForValue(LHS); + if (!Reg) + return false; + bool RegIsKill = hasTrivialKill(LHS); + Reg = fastEmitInst_extractsubreg(MVT::i32, Reg, RegIsKill, + AArch64::sub_32); + Addr.setOffsetReg(Reg); + return true; + } + break; + } } // end switch if (Addr.getReg()) { diff --git a/llvm/test/CodeGen/AArch64/fast-isel-addressing-modes.ll b/llvm/test/CodeGen/AArch64/fast-isel-addressing-modes.ll index 21fc6645009..b33c06ee278 100644 --- a/llvm/test/CodeGen/AArch64/fast-isel-addressing-modes.ll +++ b/llvm/test/CodeGen/AArch64/fast-isel-addressing-modes.ll @@ -1,5 +1,5 @@ -; RUN: llc -mtriple=aarch64-apple-darwin -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=SDAG -; RUN: llc -mtriple=aarch64-apple-darwin -O0 -fast-isel-abort -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=FAST +; RUN: llc -mtriple=aarch64-apple-darwin -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=SDAG +; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -fast-isel-abort -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=FAST ; Load / Store Base Register only define zeroext i1 @load_breg_i1(i1* %a) { @@ -425,6 +425,49 @@ define i32 @load_breg_mul_offreg_1(i64 %a, i64 %b) { ret i32 %4 } +define zeroext i8 @load_breg_and_offreg_1(i64 %a, i64 %b) { +; CHECK-LABEL: load_breg_and_offreg_1 +; CHECK: ldrb {{w[0-9]+}}, [x1, w0, uxtw] + %1 = and i64 %a, 4294967295 + %2 = add i64 %1, %b + %3 = inttoptr i64 %2 to i8* + %4 = load i8* %3 + ret i8 %4 +} + +define zeroext i16 @load_breg_and_offreg_2(i64 %a, i64 %b) { +; CHECK-LABEL: load_breg_and_offreg_2 +; CHECK: ldrh {{w[0-9]+}}, [x1, w0, uxtw #1] + %1 = and i64 %a, 4294967295 + %2 = shl i64 %1, 1 + %3 = add i64 %2, %b + %4 = inttoptr i64 %3 to i16* + %5 = load i16* %4 + ret i16 %5 +} + +define i32 @load_breg_and_offreg_3(i64 %a, i64 %b) { +; CHECK-LABEL: load_breg_and_offreg_3 +; CHECK: ldr {{w[0-9]+}}, [x1, w0, uxtw #2] + %1 = and i64 %a, 4294967295 + %2 = shl i64 %1, 2 + %3 = add i64 %2, %b + %4 = inttoptr i64 %3 to i32* + %5 = load i32* %4 + ret i32 %5 +} + +define i64 @load_breg_and_offreg_4(i64 %a, i64 %b) { +; CHECK-LABEL: load_breg_and_offreg_4 +; CHECK: ldr {{x[0-9]+}}, [x1, w0, uxtw #3] + %1 = and i64 %a, 4294967295 + %2 = shl i64 %1, 3 + %3 = add i64 %2, %b + %4 = inttoptr i64 %3 to i64* + %5 = load i64* %4 + ret i64 %5 +} + ; Load Base Register + Scaled Register Offset + Sign/Zero extension define i32 @load_breg_zext_shift_offreg_1(i32 %a, i64 %b) { ; CHECK-LABEL: load_breg_zext_shift_offreg_1 |

