[PATCH] D72710: Let combineLoadToNewType preserve ABI alignment of the load
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 08:12:32 PST 2020
aqjune created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This addresses https://bugs.llvm.org/show_bug.cgi?id=44543 by making combineLoadToNewType preserve ABI alignment of the load.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72710
Files:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/load-bitcast64.ll
Index: llvm/test/Transforms/InstCombine/load-bitcast64.ll
===================================================================
--- llvm/test/Transforms/InstCombine/load-bitcast64.ll
+++ llvm/test/Transforms/InstCombine/load-bitcast64.ll
@@ -1,12 +1,13 @@
; RUN: opt -instcombine -S < %s | FileCheck %s
-target datalayout = "p:64:64:64"
+target datalayout = "p:64:64:64-i64:32:32"
define i64* @test1(i8* %x) {
entry:
; CHECK-LABEL: @test1(
-; CHECK: load i64*, i64**
+; CHECK: [[PTR:%.*]] = bitcast i8* %x to i64*
+; CHECK: load i64*, i64** [[PTR]], align 4
; CHECK: ret
%a = bitcast i8* %x to i64*
%b = load i64, i64* %a
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -462,8 +462,12 @@
NewPtr->getType()->getPointerAddressSpace() == AS))
NewPtr = IC.Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
+ unsigned align = LI.getAlignment();
+ if (!align)
+ align = IC.getDataLayout().getABITypeAlignment(LI.getType());
+
LoadInst *NewLoad = IC.Builder.CreateAlignedLoad(
- NewTy, NewPtr, LI.getAlignment(), LI.isVolatile(), LI.getName() + Suffix);
+ NewTy, NewPtr, align, LI.isVolatile(), LI.getName() + Suffix);
NewLoad->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
copyMetadataForLoad(*NewLoad, LI);
return NewLoad;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72710.237984.patch
Type: text/x-patch
Size: 1510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200114/354654fe/attachment.bin>
More information about the llvm-commits
mailing list