AArch64 fails to select the correct addp
| Bugzilla Link | 40968 |
| Resolution | FIXED |
| Resolved on | Mar 21, 2019 15:44 |
| Version | trunk |
| OS | Linux |
| CC | @aemerson,@Arnaud-de-Grandmaison-ARM,@ornata,@smithp35,@TNorthover |
Extended Description
This code:
typedef attribute((neon_vector_type(2))) float float32x2_t; int printf(const char *, ...); static inline attribute((always_inline, nodebug)) float32x2_t vcreate_f32(unsigned long __p0) { float32x2_t __ret; __ret = (float32x2_t)(__p0); return __ret; } int main() { float32x2_t c; float32x2_t d; float32x2_t e; c = vcreate_f32(0x3f69925b3e663ec8UL); d = vcreate_f32(0x3f4375073f409923UL); e = __builtin_neon_vpadd_v(d, c, 9); float f = __builtin_neon_vget_lane_f32(e, 0); printf("%g\n", f); }
Should print ~1.51584. It seems to currently print "8.77658e+37".
This started to fail at -O0 (with global isel) after rL355344, but I think that's just because it no longer falls back to isel. It appears to be selecting ADDP (i32x2), not FADDP (f32x2).
The temporary workaround is removed as of r356722 and replaced with a proper solution of splitting the addp intrinsic into int and fp variants.
I committed a workaround: https://reviews.llvm.org/rL355865
This isn't really "solved" though since the workaround is just to always fall back to SelectionDAG when we run into this.
Yep, I agree. Making this fail without that patch just requires pulling the __builtin_neon_vpadd_v into a separate function:
typedef attribute((neon_vector_type(2))) float float32x2_t; int printf(const char *, ...); static inline attribute((always_inline, nodebug)) float32x2_t vcreate_f32(unsigned long __p0) { float32x2_t __ret; __ret = (float32x2_t)(__p0); return __ret; } float32x2_t test(float32x2_t d, float32x2_t c) { return __builtin_neon_vpadd_v(d, c, 9); } int main() { float32x2_t c; float32x2_t d; float32x2_t e; c = vcreate_f32(0x3f69925b3e663ec8UL); d = vcreate_f32(0x3f4375073f409923UL); e = test(d,c); float f = __builtin_neon_vget_lane_f32(e, 0); printf("%g\n", f); }
Yeah, this isn't actually caused by r355344.
This is actually that we don't have the information necessary to know that we need a faddp rather than an addp, so when we pattern match, we end up with the wrong add.
For example, we start out with, say, this:
%vpadd_v3 = call <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float> %vpadd_v, <2 x float> %vpadd_v2)
Which will be translated into this:
%22:fpr(<2 x s32>) = G_INTRINSIC intrinsic(@llvm.aarch64.neon.addp), %20:fpr(<2 x s32>), %21:fpr(<2 x s32>)
At this point we've entirely dropped the fact that we're working on vectors of floats. So, it's selected into this:
%22:fpr64(<2 x s32>) = ADDPv2i32 %20:fpr64(<2 x s32>), %21:fpr64(<2 x s32>)
Which is incorrect. So, we have a bit deeper of a problem here.