llvm / llvm-project

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

[optimization] gcc generate better code than clang when building complex type #98480

Open vfdff opened 1 month ago

vfdff commented 1 month ago

void foo () { for (int K = 0; K < NUM; ++K) { res[K] = complex(WORK[K], WORK[K + NUM]); } }


* gcc:

.L2: ldr q30, [x0] add x0, x0, 16 ldr q31, [x0, 8176] st2 {v30.2d - v31.2d}, [x1], 32 cmp x2, x0 bne .L2


* llvm: has 2 extra add instructions compare to gcc

.LBB0_1: // =>This Inner Loop Header: Depth=1 ldr q0, [x9] add x11, x10, x8 add x8, x8, #32 ldr q1, [x9, #8192] cmp x8, #4, lsl #12 // =16384 add x9, x9, #16 st2 { v0.2d, v1.2d }, [x11] b.ne .LBB0_1

dtcxzyw commented 1 month ago

Which pass is responsible for rewriting the loop exit condition from K != 1024 to &WORK[K] != &WORK[1024]?

Geotale commented 1 month ago

Loop strength reduction converts from idx != 1024 to offset != 16384, which stays consistent throughout the entire rest of the code