[llvm-bugs] [Bug 40243] New: [x86] horizontal op codegen miscompile

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 7 06:57:41 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40243

            Bug ID: 40243
           Summary: [x86] horizontal op codegen miscompile
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

#include <immintrin.h>
#include <stdio.h>
#include <stdalign.h>   // C11 defines _Alignas().  This header defines
alignas()

void print(__m256 in) {
  alignas(32) float v[8];
  _mm256_store_ps(v, in);
  printf("element 4: %.1f\n", v[4]);
  printf("element 7: %.1f\n", v[7]);
}

__m256 hadd(__m256 a, __m256 b) {
  float r4 = a[4] + a[5];
  float r7 = b[6] + b[7];
  __m256 r = (__m256){ a[0], a[2], b[0], b[2], r4, a[6], b[4], r7 };
  return __builtin_shufflevector(r, a, -1, -1, -1, -1, 4, -1, -1, 7);
}

int main() {
  __m256 a = _mm256_set_ps(7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0);
  __m256 b = _mm256_set_ps(15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0);
  print(hadd(a, b));
  return 0;
}

-----------------------------------------------------------------------------

$ clang checkhadd.c -mavx -O0 ; ./a.out 
element 4: 9.0
element 7: 29.0

$ clang checkhadd.c -mavx -O1 ; ./a.out 
element 4: 9.0
element 7: 13.0   <--- 14.0 + 15.0 ???

------------------------------------------------------------------------------

I think this is a long-standing bug in LowerToHorizontalOp() -- it's visible on
the shipping macOS version of clang. 

There's probably a small fix that could correct this, but given that we're also
missing horizontal patterns completely and only partially matching/optimizing
other patterns, I wonder if we should start over on that function.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190107/88aa16c9/attachment.html>


More information about the llvm-bugs mailing list