Incorrect return type of SSE2 pack intrinics
| Bugzilla Link | 5315 |
| Resolution | FIXED |
| Resolved on | Nov 05, 2009 18:12 |
| Version | unspecified |
| OS | Windows NT |
| Attachments | Proposed fix |
| Reporter | LLVM Bugzilla Contributor |
| CC | @lattner,@echristo |
Extended Description
The return type of 128-bit packssdw, packsswb and packuswb intrinsics are incorrect.
Proposed fix and AutoUpgrade patch attached.
I needed to fix up some testcases as well, but committed thusly:
Sending include/llvm/IntrinsicsX86.td Sending test/CodeGen/X86/2006-04-04-CrossBlockCrash.ll Sending test/CodeGen/X86/2006-05-01-SchedCausingSpills.ll Sending test/CodeGen/X86/2007-05-17-ShuffleISelBug.ll Sending test/CodeGen/X86/vec_zero-2.ll Transmitting file data ..... Committed revision 86203.
Yep, Nicholas is correct, I'll make sure his patch doesn't break anything and apply.
Eric, can you look at this?
Nicholas, does this affect llvm-gcc and clang at all? Do you have a testcase?
I believe they are somewhat affected as well. For instance cfe\include\clang\Basic\BuiltinsX86.def contains:
BUILTIN(__builtin_ia32_packsswb, "V8cV4sV4s", "") BUILTIN(__builtin_ia32_packssdw, "V4sV2iV2i", "") BUILTIN(__builtin_ia32_packuswb, "V8cV4sV4s", "") ... BUILTIN(__builtin_ia32_packsswb128, "V8sV8sV8s", "") BUILTIN(__builtin_ia32_packssdw128, "V4iV4iV4i", "") BUILTIN(__builtin_ia32_packuswb128, "V8sV8sV8s", "")
The upper three are MMX instructions and they have the correct return type, while the lower SSE2 ones have incorrect return types. These instructions concatenate the input vectors and truncated the elements to half their width (with saturation). So you should end up with twice the elements, with half the bits each.
Of course, SSE doesn't actually care what you store in the registers, it's just semantics. So in practice llvm-gcc and clang might actually be unaffected, assuming they bitcast the result. Nobody reported any issues with these intrinsics before, nor the clear differences between the MMX and SSE versions, so there must be bitcasts in place...
So I also don't expect any issues when fixing these semantics. Seriously, the only way to currently use these intrinsics and guarantee not to cause any issues is by bitcasting the result. Fixing the return types will make the bitcast redundant, but doesn't break it. So in practice actually my AutoUpgrade patch isn't necessary at all.
I don't have a simple test case right now. All I know is that my JIT project crashes without bitcasting the result to the right type. Frankly, just patch those damn intrinsics. :P Pretty please. :)
Nicholas, does this affect llvm-gcc and clang at all? Do you have a testcase?