While working on https://reviews.llvm.org/D150422, using Val.extractBits(8, n * 8).getZextValue() on ReadDataFromGlobal in ConstantFolding crashed in the vector-type awkward aligned case test.
Checking StoreSize on VectorType seems to match the TODO comment in tests.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
513 | This fix is correct, but incomplete: We should also add a if (!DL.typeSizeEqualsStoreSize(EltTy)) return false; here. For non-byte-sized vectors the memory layout is packed, while this code will assume that there is padding to the next byte boundary between elements. |
llvm/lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
513 | Thank you for the review! I added bailout and TODO comment and test for that! |
Thanks for the fix!
The test diff is good, we now pass the test correctly.
The code change looks reasonable to me, but I'm not very familiar with it (which is why I didn't fix it myself).
LGTM
llvm/test/Transforms/InstCombine/load-non-byte-sized-vector.ll | ||
---|---|---|
4 ↗ | (On Diff #522044) | Nit: Seems like using decimal is simpler here :) |
19 ↗ | (On Diff #522044) | The first argument of the @report function doesn't really look necessary. Actually, it would be best to split this into two tests of the form %ptr0 = getelementptr i8, ptr @foo, i64 0 %res0 = load i4, ptr %ptr0, align 1 ret i4 %res0 because this makes it easier for alive2 to verify than using function calls. |
26 ↗ | (On Diff #522044) | I'd suggest to add this test to the load.ll file. It doesn't seem worthwhile to have a separate test file for just this case. |
@nikic Thank you for the review! (Rather than returning value twice, I shorten the global array and return the one.
llvm/test/Transforms/InstCombine/load-non-byte-sized-vector.ll | ||
---|---|---|
4 ↗ | (On Diff #522044) | Thanks. Yeah, this was cargo cult coping from original byte cases ;) |
19 ↗ | (On Diff #522044) |
Thank you! I mimic the recently viewed test cases, but on these few value cases, it looks reasonable! |
19 ↗ | (On Diff #522044) | Seems reasonable! |
This fix is correct, but incomplete: We should also add a if (!DL.typeSizeEqualsStoreSize(EltTy)) return false; here. For non-byte-sized vectors the memory layout is packed, while this code will assume that there is padding to the next byte boundary between elements.