[llvm] [AMDGPU] Added min operation for MCExprs (PR #199746)
Janek van Oirschot via llvm-commits
llvm-commits at lists.llvm.org
Sun May 31 22:51:39 PDT 2026
================
@@ -499,6 +504,16 @@ static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
KBM[Expr] = std::move(KB);
return;
}
+ case AMDGPUMCExpr::VariantKind::AGVK_Min: {
+ knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
+ KnownBits KB = KBM[AGVK->getSubExpr(0)];
+ for (const MCExpr *Arg : AGVK->getArgs()) {
+ knownBitsMapHelper(Arg, KBM, Depth + 1);
+ KB = KnownBits::umin(KB, KBM[Arg]);
----------------
JanekvO wrote:
Yes, should be smax/smin
Had a look as to why this didn't show up in tests (apart from our specific resource info use-cases being on unsigned values): the unknown value needs to be a fully resolvable negative (which sounds like a bit of a contradiction). If a symbol is fully known it'll resolve through the `evaluateAsAbsolute` which correctly uses the signed `std::max/min`. I think the KnownBits max/min can be triggered here using something along the lines of `max(((external_unknown & 0) | 0x8000000000000000), 5)` which elides `evaluateAsAbsolute` for resolving but does end up with KB resolving determining it's a negative value through the bitpattern.
Sorry, a bit of a writeup that just concludes "use smax/smin" 😅
My only ask: could you add tests along the lines of `[min|max](((external_unknown & 0) | 0x8000000000000000), 5)` that showcase the codepath of KnownBits (partial-)resolving for amdgpu MCExprs? LGTM otherwise
https://github.com/llvm/llvm-project/pull/199746
More information about the llvm-commits
mailing list