[llvm] AMDGPU][True16][CodeGen] fold clamp update for true16 (PR #128919)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 13 01:34:49 PDT 2025


================
@@ -1819,7 +1819,13 @@ bool SIFoldOperandsImpl::tryFoldClamp(MachineInstr &MI) {
   if (!ClampSrc || !MRI->hasOneNonDBGUser(ClampSrc->getReg()))
     return false;
 
-  MachineInstr *Def = MRI->getVRegDef(ClampSrc->getReg());
+  // Look through COPY. COPY only observed with True16.
+  MachineOperand *DefSrc = lookUpCopyChain(*TII, *MRI, ClampSrc->getReg());
+  MachineInstr *Def = nullptr;
+  if (DefSrc && DefSrc->isReg() && !DefSrc->isImm())
+    Def = MRI->getVRegDef(DefSrc->getReg());
+  else
+    Def = MRI->getVRegDef(ClampSrc->getReg());
----------------
arsenm wrote:

```suggestion
  MachineInstr *Def = MRI->getVRegDef(DefSrc && DefSrc->isReg() ? DefSrc->getReg() : ClampSrc->getReg());

```

https://github.com/llvm/llvm-project/pull/128919


More information about the llvm-commits mailing list