[PATCH] D55169: [ConstantFolding] Handle leading zero-length elements in load folding
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 11 02:24:55 PST 2018
nikic marked an inline comment as done.
nikic added inline comments.
================
Comment at: lib/Analysis/ConstantFolding.cpp:352
// castable to implement the "load" semantic model.
- C = C->getAggregateElement(0u);
+ unsigned Elem = 0;
+ Constant *ElemC;
----------------
efriedma wrote:
> This is probably an infinite loop on something like `[4294967296 x [0 x i32]]`. (An LLVM array can have up to 2^64 elements.) Not sure how much we care... it looks like there are overflows like this all over the place in LLVM.
>
> Otherwise looks fine.
I tried
@g8 = constant [4294967296 x [0 x i32]] zeroinitializer
define i64 @test_leading_zero_size_elems_big2() {
%v = load i64, i64* bitcast ([4294967296 x [0 x i32]]* @g8 to i64*)
ret i64 %v
}
which did not result in an infinite loop ... because `ConstantAggregateZero::getNumElements()` also returns unsigned, so the number of elements is truncated to 0 :/
Still, using
@g8 = constant [4294967295 x [0 x i32]] zeroinitializer
define i64 @test_leading_zero_size_elems_big2() {
%v = load i64, i64* bitcast ([4294967295 x [0 x i32]]* @g8 to i64*)
ret i64 %v
}
ends up looping over array elements for no good reason, it's not like there is a change of finding a non-zero size elements by looking at further elements.
I think I'll change this code to handle the struct case separately, as I think it's the only one where this really makes sense.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55169/new/
https://reviews.llvm.org/D55169
More information about the llvm-commits
mailing list