diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-11-01 23:14:20 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-11-01 23:14:20 +0000 |
commit | 663ab8c1190c78a534c4bce1d6c8093537e06a72 (patch) | |
tree | 8f3f737865ad46fb80dd9d7249f0ede72fda6348 /llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp | |
parent | cfadbd947808e81f760f344477121a7028ff1edc (diff) | |
download | bcm5719-llvm-663ab8c1190c78a534c4bce1d6c8093537e06a72.tar.gz bcm5719-llvm-663ab8c1190c78a534c4bce1d6c8093537e06a72.zip |
AMDGPU: Use brev for materializing SGPR constants
This is already done with VGPR immediates and saves 4 bytes.
llvm-svn: 285765
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp')
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp index 26bc2b4e35e..7f9e9cded63 100644 --- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp +++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp @@ -206,6 +206,18 @@ static bool isKImmOrKUImmOperand(const SIInstrInfo *TII, return false; } +/// \returns true if the constant in \p Src should be replaced with a bitreverse +/// of an inline immediate. +static bool isReverseInlineImm(const SIInstrInfo *TII, + const MachineOperand &Src, + int32_t &ReverseImm) { + if (!isInt<32>(Src.getImm()) || TII->isInlineConstant(Src, 4)) + return false; + + ReverseImm = reverseBits<int32_t>(static_cast<int32_t>(Src.getImm())); + return ReverseImm >= -16 && ReverseImm <= 64; +} + /// Copy implicit register operands from specified instruction to this /// instruction that are not part of the instruction definition. static void copyExtraImplicitOps(MachineInstr &NewMI, MachineFunction &MF, @@ -290,14 +302,11 @@ bool SIShrinkInstructions::runOnMachineFunction(MachineFunction &MF) { MachineOperand &Src = MI.getOperand(1); if (Src.isImm() && TargetRegisterInfo::isPhysicalRegister(MI.getOperand(0).getReg())) { - int64_t Imm = Src.getImm(); - if (isInt<32>(Imm) && !TII->isInlineConstant(Src, 4)) { - int32_t ReverseImm = reverseBits<int32_t>(static_cast<int32_t>(Imm)); - if (ReverseImm >= -16 && ReverseImm <= 64) { - MI.setDesc(TII->get(AMDGPU::V_BFREV_B32_e32)); - Src.setImm(ReverseImm); - continue; - } + int32_t ReverseImm; + if (isReverseInlineImm(TII, Src, ReverseImm)) { + MI.setDesc(TII->get(AMDGPU::V_BFREV_B32_e32)); + Src.setImm(ReverseImm); + continue; } } } @@ -374,10 +383,19 @@ bool SIShrinkInstructions::runOnMachineFunction(MachineFunction &MF) { // Try to use S_MOVK_I32, which will save 4 bytes for small immediates. if (MI.getOpcode() == AMDGPU::S_MOV_B32) { - const MachineOperand &Src = MI.getOperand(1); + const MachineOperand &Dst = MI.getOperand(0); + MachineOperand &Src = MI.getOperand(1); - if (Src.isImm() && isKImmOperand(TII, Src)) - MI.setDesc(TII->get(AMDGPU::S_MOVK_I32)); + if (Src.isImm() && + TargetRegisterInfo::isPhysicalRegister(Dst.getReg())) { + int32_t ReverseImm; + if (isKImmOperand(TII, Src)) + MI.setDesc(TII->get(AMDGPU::S_MOVK_I32)); + else if (isReverseInlineImm(TII, Src, ReverseImm)) { + MI.setDesc(TII->get(AMDGPU::S_BREV_B32)); + Src.setImm(ReverseImm); + } + } continue; } |