[llvm-dev] [RFC] Enforcing immediate operands for intrinsics

Matt Arsenault via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 5 16:17:57 PST 2019

> On Feb 5, 2019, at 6:55 PM, Krzysztof Parzyszek via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> There is something similar going on in clang in SemaChecking.cpp. The difference is that each target can write its own verification code, which may check things like value ranges, for example.
> The scheme you're proposing would invent a new attribute (a widespread change) that only implements partial checks (i.e. "is argument immediate or not”).

This is for the benefit of IR transform passes and codegen. I’m not attempting to diagnose frontend builtins or do anything for the end user. A backend can always truncate bits or whatever to fit the actual instruction constraints if necessary. It has to do something to not crash on the IR otherwise, which is part of the problem I’m trying to solve.

> Why not simply add a function to TTI that tells you whether a particular Value is a valid n-th argument to the given intrinsic?
> Something like
>  if (TTI.isValidArgument(IntOpc, Val, OpIdx))
>    Int->setOperand(Val, OpIdx);

This is required for correctness, so TTI is not appropriate. Reasonably implementing this would still require adding something in TableGen (which then just brings you back to adding an attribute). I would also like to be able to rely on this for emission of G_INTRINISIC_* instructions in GlobalISel, so that intermediate illegal G_CONSTANT instructions can be avoided


More information about the llvm-dev mailing list