Files
Jameson Nash cf38cc0293 [clang] teach OpenCL to set the param addrspace before calling CG EmitParmDecl (#184264)
Unfortunately, this still ends up in a slightly awkward place between
Sema and CG, since a few CG phases create implicit parameters (e.g. for
`this`) which also need to be deduced into the correct address space by
Sema. This is intended to be clearly extensible for other targets that
also need this.

Changes the constructor for ImplicitParamDecl to be private again, so
that all users will go through the Create method, by making the object
ctor itself declared `protected` (like all the other VarDecl subtypes).
The memory is later cleaned up by the ASTContext bump allocator, and
since the stack is basically also a bump allocator, is is typically
equally fast. (Reverts 550d13aebb)

(If I got my commit stacked extraction right) This should allow removing
the special cases for OpenCL from EmitParmDecl once
https://github.com/llvm/llvm-project/pull/181390 lands, since this
aligns the behavior of that function with the declared intent of each
VarDecl.

This changed many tests because previously OpenCL just assumed that
allocations for parameters were actually made in the addrspace of Ty,
but didn't actually check against that properly, resulting in some
unnecessary copies. That will be fixed even more completely in
https://github.com/llvm/llvm-project/pull/181390 even more, removing
also the unnecessary addrspace casts.
2026-04-30 15:26:43 -04:00
..

IRgen optimization opportunities.

//===---------------------------------------------------------------------===//

The common pattern of
--
short x; // or char, etc
(x == 10)
--
generates an zext/sext of x which can easily be avoided.

//===---------------------------------------------------------------------===//

Bitfields accesses can be shifted to simplify masking and sign
extension. For example, if the bitfield width is 8 and it is
appropriately aligned then is is a lot shorter to just load the char
directly.

//===---------------------------------------------------------------------===//

It may be worth avoiding creation of alloca's for formal arguments
for the common situation where the argument is never written to or has
its address taken. The idea would be to begin generating code by using
the argument directly and if its address is taken or it is stored to
then generate the alloca and patch up the existing code.

In theory, the same optimization could be a win for block local
variables as long as the declaration dominates all statements in the
block.

NOTE: The main case we care about this for is for -O0 -g compile time
performance, and in that scenario we will need to emit the alloca
anyway currently to emit proper debug info. So this is blocked by
being able to emit debug information which refers to an LLVM
temporary, not an alloca.

//===---------------------------------------------------------------------===//

We should try and avoid generating basic blocks which only contain
jumps. At -O0, this penalizes us all the way from IRgen (malloc &
instruction overhead), all the way down through code generation and
assembly time.

On 176.gcc:expr.ll, it looks like over 12% of basic blocks are just
direct branches!

//===---------------------------------------------------------------------===//