diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp index d51d136ba4200c4..13de93e829fab25 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -3839,7 +3839,7 @@ AMDGPUInstructionSelector::selectVOP3PModsImpl( unsigned Mods = 0; MachineInstr *MI = MRI.getVRegDef(Src); - if (MI && MI->getOpcode() == AMDGPU::G_FNEG && + if (MI->getOpcode() == AMDGPU::G_FNEG && // It's possible to see an f32 fneg here, but unlikely. // TODO: Treat f32 fneg as only high bit. MRI.getType(Src) == LLT::fixed_vector(2, 16)) { @@ -4662,24 +4662,24 @@ AMDGPUInstructionSelector::selectMUBUFScratchOffen(MachineOperand &Root) const { // offsets. std::optional FI; Register VAddr = Root.getReg(); - if (const MachineInstr *RootDef = MRI->getVRegDef(Root.getReg())) { - Register PtrBase; - int64_t ConstOffset; - std::tie(PtrBase, ConstOffset) = getPtrBaseWithConstantOffset(VAddr, *MRI); - if (ConstOffset != 0) { - if (TII.isLegalMUBUFImmOffset(ConstOffset) && - (!STI.privateMemoryResourceIsRangeChecked() || - KB->signBitIsZero(PtrBase))) { - const MachineInstr *PtrBaseDef = MRI->getVRegDef(PtrBase); - if (PtrBaseDef->getOpcode() == AMDGPU::G_FRAME_INDEX) - FI = PtrBaseDef->getOperand(1).getIndex(); - else - VAddr = PtrBase; - Offset = ConstOffset; - } - } else if (RootDef->getOpcode() == AMDGPU::G_FRAME_INDEX) { - FI = RootDef->getOperand(1).getIndex(); + + const MachineInstr *RootDef = MRI->getVRegDef(Root.getReg()); + Register PtrBase; + int64_t ConstOffset; + std::tie(PtrBase, ConstOffset) = getPtrBaseWithConstantOffset(VAddr, *MRI); + if (ConstOffset != 0) { + if (TII.isLegalMUBUFImmOffset(ConstOffset) && + (!STI.privateMemoryResourceIsRangeChecked() || + KB->signBitIsZero(PtrBase))) { + const MachineInstr *PtrBaseDef = MRI->getVRegDef(PtrBase); + if (PtrBaseDef->getOpcode() == AMDGPU::G_FRAME_INDEX) + FI = PtrBaseDef->getOperand(1).getIndex(); + else + VAddr = PtrBase; + Offset = ConstOffset; } + } else if (RootDef->getOpcode() == AMDGPU::G_FRAME_INDEX) { + FI = RootDef->getOperand(1).getIndex(); } return {{[=](MachineInstrBuilder &MIB) { // rsrc @@ -4901,9 +4901,6 @@ AMDGPUInstructionSelector::selectMUBUFScratchOffset( std::pair AMDGPUInstructionSelector::selectDS1Addr1OffsetImpl(MachineOperand &Root) const { const MachineInstr *RootDef = MRI->getVRegDef(Root.getReg()); - if (!RootDef) - return std::pair(Root.getReg(), 0); - int64_t ConstAddr = 0; Register PtrBase; @@ -4966,9 +4963,6 @@ std::pair AMDGPUInstructionSelector::selectDSReadWrite2Impl(MachineOperand &Root, unsigned Size) const { const MachineInstr *RootDef = MRI->getVRegDef(Root.getReg()); - if (!RootDef) - return std::pair(Root.getReg(), 0); - int64_t ConstAddr = 0; Register PtrBase;