[llvm-commits] [llvm] r95266 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/objsize.ll
Eric Christopher
echristo at apple.com
Wed Feb 3 15:56:07 PST 2010
Author: echristo
Date: Wed Feb 3 17:56:07 2010
New Revision: 95266
URL: http://llvm.org/viewvc/llvm-project?rev=95266&view=rev
Log:
If we're dealing with a zero-length array, don't lower to any
particular size, we just don't know what the length is yet.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/objsize.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=95266&r1=95265&r2=95266&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Feb 3 17:56:07 2010
@@ -648,14 +648,19 @@
if (const ArrayType *AT = dyn_cast<ArrayType>(ObjTy->getElementType())) {
- // Deal with multi-dimensional arrays
+ // Deal with multi-dimensional arrays
const ArrayType *SAT = AT;
while ((AT = dyn_cast<ArrayType>(AT->getElementType())))
SAT = AT;
size_t numElems = SAT->getNumElements();
- // We return the remaining bytes, so grab the size of an element
- // in bytes.
+
+ // If numElems is 0, we don't know how large the array is so we can't
+ // make any determinations yet.
+ if (numElems == 0) break;
+
+ // We return the remaining bytes, so grab the size of an element
+ // in bytes.
size_t sizeofElem = SAT->getElementType()->getPrimitiveSizeInBits() / 8;
ConstantInt *Const =
@@ -665,7 +670,7 @@
ConstantInt::get(ReturnTy,
((numElems - indx) * sizeofElem)));
}
- }
+ }
// TODO: Add more types here.
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=95266&r1=95265&r2=95266&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Wed Feb 3 17:56:07 2010
@@ -27,4 +27,15 @@
ret i8* %2;
}
+ at window = external global [0 x i8]
+
+define i1 @baz() nounwind {
+; CHECK: @baz
+; CHECK-NEXT: llvm.objectsize.i32
+ %1 = tail call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 0), i1 false)
+ %2 = icmp eq i32 %1, -1
+ ret i1 %2
+}
+
+
declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
\ No newline at end of file
More information about the llvm-commits
mailing list