mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-26 22:26:16 +00:00
[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] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218030 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
49ab1a424d
commit
ffbd4879eb
@ -596,6 +596,29 @@ bool AArch64FastISel::computeAddress(const Value *Obj, Address &Addr, Type *Ty)
|
|||||||
if (SE->getOperand(0)->getType()->isIntegerTy(32))
|
if (SE->getOperand(0)->getType()->isIntegerTy(32))
|
||||||
Addr.setExtendType(AArch64_AM::SXTW);
|
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));
|
unsigned Reg = getRegForValue(U->getOperand(0));
|
||||||
if (!Reg)
|
if (!Reg)
|
||||||
return false;
|
return false;
|
||||||
@ -660,6 +683,37 @@ bool AArch64FastISel::computeAddress(const Value *Obj, Address &Addr, Type *Ty)
|
|||||||
Addr.setOffsetReg(Reg);
|
Addr.setOffsetReg(Reg);
|
||||||
return true;
|
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
|
} // end switch
|
||||||
|
|
||||||
if (Addr.getReg()) {
|
if (Addr.getReg()) {
|
||||||
|
@ -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 -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 -fast-isel -fast-isel-abort -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK --check-prefix=FAST
|
||||||
|
|
||||||
; Load / Store Base Register only
|
; Load / Store Base Register only
|
||||||
define zeroext i1 @load_breg_i1(i1* %a) {
|
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
|
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
|
; Load Base Register + Scaled Register Offset + Sign/Zero extension
|
||||||
define i32 @load_breg_zext_shift_offreg_1(i32 %a, i64 %b) {
|
define i32 @load_breg_zext_shift_offreg_1(i32 %a, i64 %b) {
|
||||||
; CHECK-LABEL: load_breg_zext_shift_offreg_1
|
; CHECK-LABEL: load_breg_zext_shift_offreg_1
|
||||||
|
Loading…
Reference in New Issue
Block a user