Issue 52870
Summary Optimization: Prefer 32-bit integers over 64-bit if they are in range
Labels new issue
Assignees
Reporter easyaspi314
    If LLVM knows that an integer value can fit in a 32-bit integer, it should probably do that.

On 32-bit targets it avoids expensive multiword arithmetic, and on x86_64, it can significantly reduce the number of REX prefixes resulting in smaller codegen.

For example:
```c
#include <stdint.h>

void side_effect();

void foo()
{
    for (int64_t i = 0; i < 999; i++) {
        side_effect();
    }
}
void bar()
{
    for (int32_t i = 0; i < 999; i++) {
        side_effect();
    }
}
```
Clang x86 codegen: https://godbolt.org/z/T8fo4Yare
GCC x86 codegen: https://godbolt.org/z/rsWx7Mv6M - note that GCC eliminates the 64-bit arithmetic
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to