This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold] use StoreSize for VectorType byte checking
ClosedPublic

Authored by khei4 on May 13 2023, 5:14 PM.

Details

Summary

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.

Diff Detail

Event Timeline

khei4 created this revision.May 13 2023, 5:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2023, 5:14 PM
khei4 requested review of this revision.May 13 2023, 5:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2023, 5:14 PM
khei4 edited the summary of this revision. (Show Details)May 13 2023, 5:15 PM
nikic added inline comments.May 14 2023, 2:59 AM
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.

khei4 edited the summary of this revision. (Show Details)May 14 2023, 5:40 PM
khei4 updated this revision to Diff 522044.May 14 2023, 10:26 PM

apply feedback and add test.

khei4 added inline comments.May 14 2023, 10:29 PM
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).

nikic accepted this revision.May 15 2023, 1:53 AM

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.

This revision is now accepted and ready to land.May 15 2023, 1:53 AM
khei4 updated this revision to Diff 522160.May 15 2023, 6:36 AM

apply feedbacks

khei4 added a comment.EditedMay 15 2023, 6:36 AM

@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)

because this makes it easier for alive2 to verify than using function calls.

Thank you! I mimic the recently viewed test cases, but on these few value cases, it looks reasonable!

19 ↗(On Diff #522044)

Seems reasonable!

khei4 updated this revision to Diff 522163.May 15 2023, 6:39 AM

update broken test

This revision was landed with ongoing or failed builds.May 15 2023, 7:05 AM
This revision was automatically updated to reflect the committed changes.