diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/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; diff --git a/llvm/test/Transforms/InstCombine/load-bitcast64.ll b/llvm/test/Transforms/InstCombine/load-bitcast64.ll --- a/llvm/test/Transforms/InstCombine/load-bitcast64.ll +++ b/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