Skip to content

Compiler no longer producing single horizontal add instruction after ab2c499d #49736

Closed
@dyung

Description

@dyung
Bugzilla Link 50392
Version trunk
OS All
CC @alexey-bataev,@anton-afanasyev,@RKSimon

Extended Description

One of our internal tests compiles the following code and verifies that it generates a horizontal add instruction in the resulting assembly when optimizations are enabled and targeting btver2.

__attribute__((noinline))
__m256d add_pd_002(__m256d a, __m256d b) {
  __m256d r = (__m256d){ a[0] + a[1], a[2] + a[3], b[0] + b[1], b[2] + b[3] };
  return __builtin_shufflevector(r, a, 0, -1, 2, 3);
}

Prior to commit ab2c499, when compiled with "-g0 -O3 -march=btver2", the compiler would produce the following code:

        vinsertf128     $1, %xmm1, %ymm0, %ymm0
        vhaddpd %ymm1, %ymm0, %ymm0

But following the mentioned change, the compiler is now producing the following code instead:

        vextractf128    $1, %ymm1, %xmm2
        vhaddpd %xmm0, %xmm0, %xmm0
        vhaddpd %xmm2, %xmm1, %xmm1
        vperm2f128      $2, %ymm0, %ymm1, %ymm0 # ymm0 = ymm0[0,1],ymm1[0,1]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions