[PATCH] D17042: AMDGPU/SI: move SMRD to flat if UseFlatForGlobal is true

Changpeng Fang via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 15 16:37:48 PST 2016


cfang added inline comments.

================
Comment at: lib/Target/AMDGPU/SIInstrInfo.cpp:2379-2397
@@ -2336,1 +2378,21 @@
+
+        if (OffsetOpnd->isReg()) {
+          RegOffset = OffsetOpnd->getReg();
+          HasOffset = true;
+        } else {
+          assert(OffsetOpnd->isImm());
+          ImmOffset = OffsetOpnd->getImm();
+          // SMRD instructions take a dword offsets on SI/CI and byte offset on VI
+          // and FLAT instructions always take a byte offset.
+          if (ST.getGeneration() <= AMDGPUSubtarget::SEA_ISLANDS)
+            ImmOffset <<= 2;
+          HasOffset = (ImmOffset != 0);
+          if (ImmOffset > 64) { // Could not be inlined!
+            RegOffset = MRI.createVirtualRegister(&AMDGPU::SGPR_32RegClass);
+            BuildMI(*MBB, MI, DL, get(AMDGPU::S_MOV_B32),
+                    RegOffset)
+                    .addImm(ImmOffset);
+            ImmOffset = 0;
+          }
+        }
 
----------------
tstellarAMD wrote:
> This code is very similar to what we have in the non-FlatForGlobal path.  Can we put this code into its own function so we can share it between the two paths.
Yes, the code is similar on both paths. But to me, it is not that easy for them to share the same code.

I can introduce a function to return the immediate and register offsets for a smrd instruction. but I still have to handle 
the immediate separately. Also, for the flat path, I want to save the 64-bit addition when the immediate offset is 0.
This will make the code sharing a little "ugly".



http://reviews.llvm.org/D17042





More information about the llvm-commits mailing list