diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/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); diff --git a/llvm/test/CodeGen/X86/split-store.ll b/llvm/test/CodeGen/X86/split-store.ll --- a/llvm/test/CodeGen/X86/split-store.ll +++ b/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 +}