Help Emitting Proper Immediates

Jeff Law jeffreyalaw@gmail.com
Tue Nov 11 14:27:18 GMT 2025



On 11/10/25 7:29 PM, Shivam Patel via Gcc-help wrote:
> Hi,
> 
> I'm working on a GCC backend for an extensible hobbyist ISA. I'm trying to start by targeting the version with no extensions, in which the largest immediate allowed for arithmetic and logical operations is 5 bits. When building libgcc for this target, I see that my predicates and patterns are not preventing GCC from emitting immediates outside the 5-bit range. Here's an example error caused by _muldi3:
I would check if "general_operand" is returning true/false for the 
operand in question.  I suspect it's returning true.  Your predicate is 
probably also accepting symbolic operands, which I doubt you really want 
to do.

I would allow CONST_INT, REG, SUBREG, but not CONST.

And instead of checking "general_operand" use "register_operand".

That should get you started.  Your constraints are too wide as well 
(accept any integer), you should define a constraint for the immediates 
allowed by this class of instructions.

jeff


More information about the Gcc-help mailing list