[clang] FEAT: 1 byte for "true" & "false" (PR #138713)

SAKSHAM JOSHI via cfe-commits cfe-commits at lists.llvm.org
Thu May 8 08:29:01 PDT 2025


saksham-joshi wrote:

> > Yeah! you are right that the size depends on the variable, but I never said to create a variable.
> > Suppose I have two functions performing same process but one is returning bool and other one is returning int.
> > 
> > 1. bool fnc1() { return (_Bool)true; }
> > 2. int fnc2(){ return true; }
> > 
> > Can you please tell me which of the above 2 function will be more efficient?
> 
> Again, in this case the "efficiency" of these functions does not depend on how you declare true and false, but rather on what return type each function has.
> 
> But the impact of type change is also questionable. Per modern calling conventions, the return value of a function is stored in a CPU register, and the size of that register is usually 4 or 8 bytes. Even if one decides to return a 1-byte value, there won't be much difference for the CPU. (Well, on x86 you can return the 1-byte value in AL, but this won't lead to faster code).
> 
> > If this is also the case with Clang, then my work is done here.
> 
> Yes, this is also the case.

Okay, I got it!
Thank you so much Mr. Ramosian Glider

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


More information about the cfe-commits mailing list