[PATCH] D95432: AMDGPU/GlobalISel: Combine uniform icmp with one use

Petar Avramovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 04:40:13 PST 2021


Petar.Avramovic added inline comments.


================
Comment at: llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp:76-77
+  Register Condition = getConditionOp(MI).getReg();
+  if (!isSgprRegBank(Condition) || !MRI.hasOneNonDBGUse(Condition))
+    return false;
+
----------------
arsenm wrote:
> I don't think this really needs a one use check. Consider the case where another use already exists without the intermediate casts:
> 
> %x:s32 = G_ICMP
> %y:s1 = G_TRUNC %x
> %z:s32 = G_ZEXT %y
> %select0 = G_SELECT %x
> %select1 = G_SELECT %z
I wanted to keep this as simple as possible and cover most common case (single use).
Can we get mir like that? Regbankselect independently legalizes sgpr icmp and select. ICMP gets followed by G_TRUNC and G_SELECT has to G_ZEXT input condition. I would expect something like this:
```
%x:s32 = G_ICMP
%y:s1 = G_TRUNC %x
...
%z:s32 = G_ZEXT %y
%select1 = G_SELECT %z
...
%w:s32 = G_ZEXT %y
%select0 = G_SELECT %w
```
Maybe we could cover this case for select, are there more?
Afaik only trunc can end up having multiple uses. So we have to check G_TRUNC uses and find the one that Helper.dominates other uses. If this happens to be our G_ZEXT then move icmp before select and trunc after select, like this:
```
...
%z:s32 = G_ZEXT %y //dead
%x:s32 = G_ICMP
%select1 = G_SELECT %x
%y:s1 = G_TRUNC %x
...
%w:s32 = G_ZEXT %y
%select0 = G_SELECT %w
```



================
Comment at: llvm/test/CodeGen/AMDGPU/GlobalISel/combine-move-uniform-icmp-with-one-use.mir:34-35
+    %8:sgpr(s1) = G_TRUNC %12(s32)
+    %9:sgpr(s32) = G_CONSTANT i32 268435455
+    %10:sgpr(s32) = G_AND %2, %9
+    %13:sgpr(s32) = G_ZEXT %8(s1)
----------------
Combine targets specific case when there are instructions between uniform G_ICMP and G_SELECT/G_BRCOND. Zext and trunc are there but combining them has no effect on having to temporary save scc. We have to move icmp. Also since Zext and trunc  have no effect on selected instruction we don't move them and just leave them to be removed as dead instructions.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95432/new/

https://reviews.llvm.org/D95432



More information about the llvm-commits mailing list