llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
327 stars 86 forks source link

Remove redundant bitcast in builtin dynamic alloca codegen #554

Open orbiri opened 3 months ago

orbiri commented 3 months ago

AllocaOp verifies that the returned address type is the pointer of the allocated type, e.g. u64 * and u64. The dynamic allocation builtins, in general, are allocating buffers of size size bytes and returning void * pointers. To support this in #547, we introduced an AllocaOp of type u8, and had to later on bitcast the return address to void *. Usually right afterwards, the user of the builtin dynamic alloca will cast the operation to its intended value, e.g.

int *a = (int *)__builtin_alloca(sizeof(int) * size);

We should define a method to remove this redundant bitcasts by either (or both):