[llvm] r280972 - AMDGPU: Try to commute when selecting s_addk_i32/s_mulk_i32

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 10:35:42 PDT 2016


Author: arsenm
Date: Thu Sep  8 12:35:41 2016
New Revision: 280972

URL: http://llvm.org/viewvc/llvm-project?rev=280972&view=rev
Log:
AMDGPU: Try to commute when selecting s_addk_i32/s_mulk_i32

Modified:
    llvm/trunk/lib/Target/AMDGPU/SIShrinkInstructions.cpp
    llvm/trunk/test/CodeGen/AMDGPU/s_addk_i32.ll
    llvm/trunk/test/CodeGen/AMDGPU/s_mulk_i32.ll

Modified: llvm/trunk/lib/Target/AMDGPU/SIShrinkInstructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIShrinkInstructions.cpp?rev=280972&r1=280971&r2=280972&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIShrinkInstructions.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIShrinkInstructions.cpp Thu Sep  8 12:35:41 2016
@@ -286,22 +286,27 @@ bool SIShrinkInstructions::runOnMachineF
       // satisfied.
       if (MI.getOpcode() == AMDGPU::S_ADD_I32 ||
           MI.getOpcode() == AMDGPU::S_MUL_I32) {
-        const MachineOperand &Dest = MI.getOperand(0);
-        const MachineOperand &Src0 = MI.getOperand(1);
-        const MachineOperand &Src1 = MI.getOperand(2);
+        const MachineOperand *Dest = &MI.getOperand(0);
+        MachineOperand *Src0 = &MI.getOperand(1);
+        MachineOperand *Src1 = &MI.getOperand(2);
+
+        if (!Src0->isReg() && Src1->isReg()) {
+          if (TII->commuteInstruction(MI, false, 1, 2))
+            std::swap(Src0, Src1);
+        }
 
         // FIXME: This could work better if hints worked with subregisters. If
         // we have a vector add of a constant, we usually don't get the correct
         // allocation due to the subregister usage.
-        if (TargetRegisterInfo::isVirtualRegister(Dest.getReg()) &&
-            Src0.isReg()) {
-          MRI.setRegAllocationHint(Dest.getReg(), 0, Src0.getReg());
-          MRI.setRegAllocationHint(Src0.getReg(), 0, Dest.getReg());
+        if (TargetRegisterInfo::isVirtualRegister(Dest->getReg()) &&
+            Src0->isReg()) {
+          MRI.setRegAllocationHint(Dest->getReg(), 0, Src0->getReg());
+          MRI.setRegAllocationHint(Src0->getReg(), 0, Dest->getReg());
           continue;
         }
 
-        if (Src0.isReg() && Src0.getReg() == Dest.getReg()) {
-          if (Src1.isImm() && isKImmOperand(TII, Src1)) {
+        if (Src0->isReg() && Src0->getReg() == Dest->getReg()) {
+          if (Src1->isImm() && isKImmOperand(TII, *Src1)) {
             unsigned Opc = (MI.getOpcode() == AMDGPU::S_ADD_I32) ?
               AMDGPU::S_ADDK_I32 : AMDGPU::S_MULK_I32;
 

Modified: llvm/trunk/test/CodeGen/AMDGPU/s_addk_i32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/s_addk_i32.ll?rev=280972&r1=280971&r2=280972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/s_addk_i32.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/s_addk_i32.ll Thu Sep  8 12:35:41 2016
@@ -91,3 +91,19 @@ define void @no_s_addk_i32_k0(i32 addrsp
   store i32 %add, i32 addrspace(1)* %out
   ret void
 }
+
+ at lds = addrspace(3) global [512 x i32] undef, align 4
+
+; SI-LABEL: {{^}}commute_s_addk_i32:
+; SI: s_addk_i32 s{{[0-9]+}}, 0x800{{$}}
+define void @commute_s_addk_i32(i32 addrspace(1)* %out, i32 %b) #0 {
+  %size = call i32 @llvm.amdgcn.groupstaticsize()
+  %add = add i32 %size, %b
+  call void asm sideeffect "; foo $0, $1", "v,s"([512 x i32] addrspace(3)* @lds, i32 %add)
+  ret void
+}
+
+declare i32 @llvm.amdgcn.groupstaticsize() #1
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind readnone }

Modified: llvm/trunk/test/CodeGen/AMDGPU/s_mulk_i32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/s_mulk_i32.ll?rev=280972&r1=280971&r2=280972&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/s_mulk_i32.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/s_mulk_i32.ll Thu Sep  8 12:35:41 2016
@@ -39,3 +39,19 @@ define void @no_s_mulk_i32_k0(i32 addrsp
   store i32 %mul, i32 addrspace(1)* %out
   ret void
 }
+
+ at lds = addrspace(3) global [512 x i32] undef, align 4
+
+; SI-LABEL: {{^}}commute_s_mulk_i32:
+; SI: s_mulk_i32 s{{[0-9]+}}, 0x800{{$}}
+define void @commute_s_mulk_i32(i32 addrspace(1)* %out, i32 %b) #0 {
+  %size = call i32 @llvm.amdgcn.groupstaticsize()
+  %add = mul i32 %size, %b
+  call void asm sideeffect "; foo $0, $1", "v,s"([512 x i32] addrspace(3)* @lds, i32 %add)
+  ret void
+}
+
+declare i32 @llvm.amdgcn.groupstaticsize() #1
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind readnone }




More information about the llvm-commits mailing list