Bug 399287

Summary: amd64 front end: Illegal Instruction vcmptrueps
Product: [Developer tools] valgrind Reporter: dwwork
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: paolo
Priority: NOR    
Version First Reported In: 3.13.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Small C program illustrating the problem

Description dwwork 2018-10-01 17:16:17 UTC
Created attachment 115345 [details]
Small C program illustrating the problem

SUMMARY

Using Valgrind 3.13, Valgrind is failing with an illegal instruction error. 
The instruction is vcmptrueps, which can be manually created with the _mm_cmp_ps() intrinsic. (Documentation: https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_cmp_ps&expand=719,719&techs=AVX)

I have attached a small program that reproduces the problem.

We see the problem with Clang 5.0.1 and GCC 7.3. (It seems that different versions interpret this intrinsic differently, so YMMV.) If I have the compiler output the assembly (-s flag), the vcmptrueps instruction doesn't show up. If I attach to the vgdb server and look at the highlighted instruction when valgrind sends the SIGILL signal, then it shows up. I'm not sure why they are different. I'm not an expert, I'm afraid.
Comment 1 dwwork 2018-10-01 17:23:42 UTC
I should comment that for simplicity, I compiled the test program with '-mavx -g'. The -mavx is needed, as the intrinsic is part of the AVX instruction set.
Comment 2 Julian Seward 2019-03-12 18:24:34 UTC
Well, I can reproduce this, and I see why it fails.  The thing is,
I'm not sure why you'd want to generate this instruction in the
first place.  It ignores its operands and returns "true" in each
lane (that is, 4 lanes of 0xFFFFFFFF).

V handles these comparisons ok in the case where it really is actually
a comparison.  But for these always-true/always-false cases, I can't
think of a quick fix.  You might want to have a look at findSSECmpOp()
in guest_amd64_toIR.c; VCMPTRUEPS is the missing case 0xF.
Comment 3 Julian Seward 2019-03-13 13:29:53 UTC
Fixed:
ecc4e970936b8ab2057f0a899d220ac611e83c3e implementation
ea09451baf13c13dfea3869b0df34b677e0557bb test cases
Comment 4 Mark Wielaard 2019-04-19 23:28:14 UTC
*** Bug 406669 has been marked as a duplicate of this bug. ***