[PATCH] D72710: [InstCombine] Let combineLoadToNewType preserve ABI alignment of the load (PR44543)

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 09:27:20 PST 2020


aqjune updated this revision to Diff 238003.
aqjune added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72710/new/

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,15 @@
         NewPtr->getType()->getPointerAddressSpace() == AS))
     NewPtr = IC.Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
 
+  unsigned Align = LI.getAlignment();
+  if (!Align)
+    // If old load did not have an explicit alignment specified,
+    // manually preserve the implied (ABI) alignment of the load.
+    // Else we may inadvertently incorrectly over-promise alignment.
+    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.238003.patch
Type: text/x-patch
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200114/872cf0b4/attachment.bin>


More information about the llvm-commits mailing list