$OpenBSD: patch-lib_Target_PowerPC_PPCISelLowering_cpp,v 1.6 2019/07/07 14:04:07 jca Exp $

When generating code for OpenBSD/powerpc, avoid unaligned floating-point
load and store instructions.  The vast majority of PowerPC CPUs that
OpenBSD runs on don't implement those and will generate an alignment
exceptions.  While we do emulate lfd and stfd (to work around GCC bugs),
we don't emulate lfs and stfs.  It is way more efficient to have the
compiler generate code that only uses aligned load and store instructions.

Index: lib/Target/PowerPC/PPCISelLowering.cpp
--- lib/Target/PowerPC/PPCISelLowering.cpp.orig
+++ lib/Target/PowerPC/PPCISelLowering.cpp
@@ -14204,6 +14204,14 @@ bool PPCTargetLowering::allowsMisalignedMemoryAccesses
   if (VT == MVT::ppcf128)
     return false;
 
+  if (Subtarget.isTargetOpenBSD()) {
+    // Traditional PowerPC does not support unaligned memory access
+    // for floating-point and the OpenBSD kernel does not emulate
+    // all possible floating-point load and store instructions.
+    if (VT == MVT::f32 || VT == MVT::f64)
+      return false;
+  }
+
   if (Fast)
     *Fast = true;
 
