llvm.org GIT mirror llvm / 41b33f4
PR4286: Make RewriteLoadUserOfWholeAlloca and RewriteStoreUserOfWholeAlloca deal with tail padding because isSafeUseOfBitCastedAllocation expects them to. Otherwise, we crash trying to erase the bitcast. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72688 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 10 years ago
2 changed file(s) with 30 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
902902
903903 // If this isn't a store of an integer to the whole alloca, it may be a store
904904 // to the first element. Just ignore the store in this case and normal SROA
905 // will handle it. We don't handle types here that have tail padding, like
906 // an alloca of type {i1}.
905 // will handle it.
907906 if (!isa(SrcVal->getType()) ||
908 TD->getTypeSizeInBits(SrcVal->getType()) != AllocaSizeBits)
907 TD->getTypeAllocSizeInBits(SrcVal->getType()) != AllocaSizeBits)
909908 return;
909 // Handle tail padding by extending the operand
910 if (TD->getTypeSizeInBits(SrcVal->getType()) != AllocaSizeBits)
911 SrcVal = new ZExtInst(SrcVal, IntegerType::get(AllocaSizeBits), "", SI);
910912
911913 DOUT << "PROMOTING STORE TO WHOLE ALLOCA: " << *AI << *SI;
912914
10151017
10161018 // If this isn't a load of the whole alloca to an integer, it may be a load
10171019 // of the first element. Just ignore the load in this case and normal SROA
1018 // will handle it. We don't handle types here that have tail padding, like
1019 // an alloca of type {i1}.
1020 // will handle it.
10201021 if (!isa(LI->getType()) ||
1021 TD->getTypeSizeInBits(LI->getType()) != AllocaSizeBits)
1022 TD->getTypeAllocSizeInBits(LI->getType()) != AllocaSizeBits)
10221023 return;
10231024
10241025 DOUT << "PROMOTING LOAD OF WHOLE ALLOCA: " << *AI << *LI;
10341035 ArrayEltBitOffset = TD->getTypeAllocSizeInBits(ArrayEltTy);
10351036 }
10361037
1037 Value *ResultVal = Constant::getNullValue(LI->getType());
1038 Value *ResultVal = Constant::getNullValue(IntegerType::get(AllocaSizeBits));
10381039
10391040 for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
10401041 // Load the value from the alloca. If the NewElt is an aggregate, cast
10811082
10821083 ResultVal = BinaryOperator::CreateOr(SrcField, ResultVal, "", LI);
10831084 }
1084
1085
1086 // Handle tail padding by truncating the result
1087 if (TD->getTypeSizeInBits(LI->getType()) != AllocaSizeBits)
1088 ResultVal = new TruncInst(ResultVal, LI->getType(), "", LI);
1089
10851090 LI->replaceAllUsesWith(ResultVal);
10861091 LI->eraseFromParent();
10871092 }
0 ; RUN: llvm-as < %s | opt -scalarrepl
1 ; PR4286
2
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4 target triple = "x86_64-undermydesk-freebsd8.0"
5 %struct.singlebool = type <{ i8 }>
6
7 define zeroext i8 @doit() nounwind {
8 entry:
9 %a = alloca %struct.singlebool, align 1 ; <%struct.singlebool*> [#uses=2]
10 %storetmp.i = bitcast %struct.singlebool* %a to i1* ; [#uses=1]
11 store i1 true, i1* %storetmp.i
12 %tmp = getelementptr %struct.singlebool* %a, i64 0, i32 0 ; [#uses=1]
13 %tmp1 = load i8* %tmp ; [#uses=1]
14 ret i8 %tmp1
15 }
16