[PATCH] D74311: [CodeGen] Fix the computation of the alignment of split stores.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 05:34:36 PST 2020


courbet created this revision.
courbet added reviewers: gchatelet, spatel, lebedev.ri.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Right now the alignment of the lower half of a store is computed as
align/2, which fails for unaligned stores (align = 1), and is overly
pessimitic for, e.g. a 8 byte store aligned to 4 bytes.
Fixes PR44851


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74311

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/test/CodeGen/X86/split-store-unaligned.ll
  llvm/test/CodeGen/X86/split-store.ll


Index: llvm/test/CodeGen/X86/split-store.ll
===================================================================
--- llvm/test/CodeGen/X86/split-store.ll
+++ llvm/test/CodeGen/X86/split-store.ll
@@ -275,3 +275,19 @@
 exitbb:
   ret void
 }
+
+; See D73907
+define void @ttml_read_coords(float %x, i64* %p) {
+; CHECK-LABEL: ttml_read_coords:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    movss %xmm0, (%rdi)
+; CHECK-NEXT:    movl $0, 4(%rdi)
+; CHECK-NEXT:    retq
+  %b = bitcast float %x to i32
+  %z = zext i32 0 to i64
+  %s = shl nuw nsw i64 %z, 32
+  %z2 = zext i32 %b to i64
+  %o = or i64 %s, %z2
+  store i64 %o, i64* %p, align 1
+  ret void
+}
Index: llvm/test/CodeGen/X86/split-store-unaligned.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/split-store-unaligned.ll
@@ -0,0 +1,14 @@
+; RUN: opt -codegenprepare -O2 -mtriple=i686-w64-windows-gnu
+
+target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-w64-windows-gnu"
+
+define void @ttml_read_coords(float %x, i64* %p) {
+  %b = bitcast float %x to i32
+  %z = zext i32 0 to i64
+  %s = shl nuw nsw i64 %z, 32
+  %z2 = zext i32 %b to i64
+  %o = or i64 %s, %z2
+  store i64 %o, i64* %p, align 1
+  ret void
+}
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -6868,8 +6868,13 @@
       Addr = Builder.CreateGEP(
           SplitStoreType, Addr,
           ConstantInt::get(Type::getInt32Ty(SI.getContext()), 1));
-    Builder.CreateAlignedStore(V, Addr,
-                               Upper ? SI.getAlign() / 2 : SI.getAlign());
+    MaybeAlign Alignment = SI.getAlign();
+    if (Upper && SI.getAlign()) {
+      // When the original store is aligned, the lower part has the same alignment.
+      // Find the best alignment for the upper part. 
+      Alignment = commonAlignment(SI.getAlign(), HalfValBitSize / 8);
+    }
+    Builder.CreateAlignedStore(V, Addr, Alignment);
   };
 
   CreateSplitStore(LValue, false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74311.243521.patch
Type: text/x-patch
Size: 2164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200210/b06e9daf/attachment.bin>


More information about the llvm-commits mailing list