1 //===-- SILowerI1Copies.cpp - Lower I1 Copies -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 /// i1 values are usually inserted by the CFG Structurize pass and they are
9 /// unique in that they can be copied from VALU to SALU registers.
10 /// This is not possible for any other value type. Since there are no
11 /// MOV instructions for i1, we to use V_CMP_* and V_CNDMASK to move the i1.
13 //===----------------------------------------------------------------------===//
16 #define DEBUG_TYPE "si-i1-copies"
18 #include "SIInstrInfo.h"
19 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
20 #include "llvm/CodeGen/MachineDominators.h"
21 #include "llvm/CodeGen/MachineFunctionPass.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Target/TargetMachine.h"
33 class SILowerI1Copies : public MachineFunctionPass {
38 SILowerI1Copies() : MachineFunctionPass(ID) {
39 initializeSILowerI1CopiesPass(*PassRegistry::getPassRegistry());
42 virtual bool runOnMachineFunction(MachineFunction &MF) override;
44 virtual const char *getPassName() const override {
45 return "SI Lower il Copies";
48 virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
49 AU.addRequired<MachineDominatorTree>();
51 MachineFunctionPass::getAnalysisUsage(AU);
55 } // End anonymous namespace.
57 INITIALIZE_PASS_BEGIN(SILowerI1Copies, DEBUG_TYPE,
58 "SI Lower il Copies", false, false)
59 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
60 INITIALIZE_PASS_END(SILowerI1Copies, DEBUG_TYPE,
61 "SI Lower il Copies", false, false)
63 char SILowerI1Copies::ID = 0;
65 char &llvm::SILowerI1CopiesID = SILowerI1Copies::ID;
67 FunctionPass *llvm::createSILowerI1CopiesPass() {
68 return new SILowerI1Copies();
71 bool SILowerI1Copies::runOnMachineFunction(MachineFunction &MF) {
72 MachineRegisterInfo &MRI = MF.getRegInfo();
73 const SIInstrInfo *TII = static_cast<const SIInstrInfo *>(
74 MF.getTarget().getInstrInfo());
75 const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo();
77 for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
80 MachineBasicBlock &MBB = *BI;
81 MachineBasicBlock::iterator I, Next;
82 for (I = MBB.begin(); I != MBB.end(); I = Next) {
84 MachineInstr &MI = *I;
86 if (MI.getOpcode() == AMDGPU::V_MOV_I1) {
87 MI.setDesc(TII->get(AMDGPU::V_MOV_B32_e32));
91 if (MI.getOpcode() != AMDGPU::COPY ||
92 !TargetRegisterInfo::isVirtualRegister(MI.getOperand(0).getReg()) ||
93 !TargetRegisterInfo::isVirtualRegister(MI.getOperand(1).getReg()))
97 const TargetRegisterClass *DstRC =
98 MRI.getRegClass(MI.getOperand(0).getReg());
99 const TargetRegisterClass *SrcRC =
100 MRI.getRegClass(MI.getOperand(1).getReg());
102 if (DstRC == &AMDGPU::VReg_1RegClass &&
103 TRI->getCommonSubClass(SrcRC, &AMDGPU::SGPR_64RegClass)) {
104 BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(AMDGPU::V_CNDMASK_B32_e64))
105 .addOperand(MI.getOperand(0))
108 .addOperand(MI.getOperand(1))
113 MI.eraseFromParent();
114 } else if (TRI->getCommonSubClass(DstRC, &AMDGPU::SGPR_64RegClass) &&
115 SrcRC == &AMDGPU::VReg_1RegClass) {
116 BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(AMDGPU::V_CMP_NE_I32_e64))
117 .addOperand(MI.getOperand(0))
119 .addOperand(MI.getOperand(1))
124 MI.eraseFromParent();