llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.03k stars 11.97k forks source link

GCC generate better code than Clang related to the update of memory address on AArch64 #62935

Open vfdff opened 1 year ago

vfdff commented 1 year ago
llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-aarch64

fhahn commented 1 year ago

This looks like a backend issue and nothing LV can improve on.

Interestingly, if the IR generated by clang (-emit-llvm) is passed directly to llc, we get the desired results: https://llvm.godbolt.org/z/T9PdbaPTj

momchil-velikov commented 1 year ago

Data point: looks nicer with -lsr-preferred-addressing-mode=postindexed https://gcc.godbolt.org/z/7dK1rxv4j

vfdff commented 1 year ago

This looks like a backend issue and nothing LV can improve on.

Interestingly, if the IR generated by clang (-emit-llvm) is passed directly to llc, we get the desired results: https://llvm.godbolt.org/z/T9PdbaPTj

The different begin with the IR Dump After Loop Strength Reduction (loop-reduce)

Further, I found that the order of user passed to llc is reversed (can be dumped with -debug-only=iv-users), but I don't know how to further track the order of I->uses()?

https://github.com/llvm/llvm-project/blob/f3202b9da663fb618ea4e3dc75a1352bdb2f969a/llvm/lib/Analysis/IVUsers.cpp#LL174C22-L174C22