Fix PR5551 by not ignoring the top level constantexpr when
authorChris Lattner <sabre@nondot.org>
Fri, 4 Dec 2009 06:29:29 +0000 (06:29 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 4 Dec 2009 06:29:29 +0000 (06:29 +0000)
folding a load from constant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90545 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/ConstProp/loads.ll

index 4b0b9a54c774bcc474c9b66386351f53e6266e6b..eaf90d014ffebf72b47f2a1ffb962984972bd6a8 100644 (file)
@@ -432,7 +432,7 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
   // Instead of loading constant c string, use corresponding integer value
   // directly if string length is small enough.
   std::string Str;
-  if (TD && GetConstantStringInfo(CE->getOperand(0), Str) && !Str.empty()) {
+  if (TD && GetConstantStringInfo(CE, Str) && !Str.empty()) {
     unsigned StrLen = Str.length();
     const Type *Ty = cast<PointerType>(CE->getType())->getElementType();
     unsigned NumBits = Ty->getPrimitiveSizeInBits();
index edd26b8772540271f56556a36e254b291e2a6878..9151d256b02499a3584157b4174b910016c9e776 100644 (file)
@@ -101,3 +101,12 @@ entry:
 }
 
 
+; PR5551
+@test12g = private constant [6 x i8] c"a\00b\00\00\00"
+
+define i16 @test12() {
+  %a = load i16* getelementptr inbounds ([3 x i16]* bitcast ([6 x i8]* @test12g to [3 x i16]*), i32 0, i64 1) 
+  ret i16 %a
+; CHECK: @test12
+; CHECK: ret i16 98
+}