This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Preserve metadata when combining select+binop
ClosedPublic

Authored by chfast on Jul 17 2023, 7:08 AM.

Diff Detail

Event Timeline

chfast created this revision.Jul 17 2023, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 7:08 AM
chfast requested review of this revision.Jul 17 2023, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 7:08 AM
chfast added inline comments.Jul 17 2023, 7:11 AM
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
541

I believe there are more case in the file where metadata copy is missed. I will try to identify them and create more tests cases. Can be in this review on later, depending on reviewers' suggestion.

llvm/test/Transforms/InstCombine/unpredictable-select.ll
1 ↗(On Diff #541012)

I created this test file. Is this good location?

goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
541

Are there any other binops you want to preserve this flag for?

llvm/test/Transforms/InstCombine/unpredictable-select.ll
1 ↗(On Diff #541012)

Its fine.

Can you make the summary a bit more explinatory than just "fixed..."

nikic added a subscriber: nikic.
nikic added inline comments.
llvm/test/Transforms/InstCombine/unpredictable-select.ll
1 ↗(On Diff #541012)

I would add this to the select_meta.ll test.

chfast added inline comments.Jul 18 2023, 12:48 AM
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
541

I think it make sense for any binop because the condition of the select in this transformation remains unchanged (i.e. !unpredictable is still applicable).

goldstein.w.n added inline comments.Jul 18 2023, 8:49 AM
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
541

I think you have this in the right place for most binops, but you should probably add additional tests for things like:
sub, or, xor, and, mul, div, rem, llvm.min, llvm.max, etc...

you probably don't need all but some variety of those (like 1/2 bitwise, div or rem, a few intrinsics) should provide better coverage.

llvm/test/Transforms/InstCombine/unpredictable-select.ll
1 ↗(On Diff #541012)

+1

chfast updated this revision to Diff 541927.Jul 19 2023, 3:02 AM

Rebased on new tests cases.

chfast added inline comments.Jul 19 2023, 3:05 AM
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
541

I added tests for most instructions from getSelectFoldableOperands. There are no any intrinsics there.

chfast retitled this revision from [InstCombine] Keep !unpredictable when combining select+add to [InstCombine] Preserve metadata when combining select+binop.Jul 19 2023, 3:05 AM
nikic accepted this revision.Jul 19 2023, 3:26 AM

LGTM

llvm/test/Transforms/InstCombine/select_meta.ll
317–318

Drop the TODOs.

This revision is now accepted and ready to land.Jul 19 2023, 3:26 AM
chfast updated this revision to Diff 541950.Jul 19 2023, 4:14 AM

Removed TODO comments from tests.