This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold pattern xor(and, or) to select
ClosedPublic

Authored by bcl5980 on Jan 12 2023, 11:44 PM.

Diff Detail

Event Timeline

bcl5980 created this revision.Jan 12 2023, 11:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 11:44 PM
bcl5980 requested review of this revision.Jan 12 2023, 11:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 11:44 PM
spatel added inline comments.Jan 17 2023, 5:30 AM
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
4270

Capitalize variable name: "NeedFreeze"

llvm/test/Transforms/InstCombine/xor-and-or.ll
4

How does this example already get optimized? Can we remove the code that handled it?

200–201

Remove TODO comment.

214–215

Remove TODO comment.

bcl5980 added inline comments.Jan 17 2023, 7:49 PM
llvm/test/Transforms/InstCombine/xor-and-or.ll
4

This pattern is optimized in SimplifySelectsFeedingBinaryOp.

(A ? B : C) op (A ? E : F) -> A ? (B op E) : (C op F)

I don't think we can remove the code as it can handle not only i1 types.

bcl5980 updated this revision to Diff 490025.Jan 17 2023, 7:55 PM
spatel accepted this revision.Jan 18 2023, 5:30 AM

LGTM

llvm/test/Transforms/InstCombine/xor-and-or.ll
200

typo: through -> though

If there's evidence that this is worse in codegen, then we could restrict the transform in this patch - only change when one or more of the original instructions is a select?

This revision is now accepted and ready to land.Jan 18 2023, 5:30 AM
bcl5980 added inline comments.Jan 18 2023, 9:18 PM
llvm/test/Transforms/InstCombine/xor-and-or.ll
200

https://godbolt.org/z/7hPWbK9oT
It looks the drop comes from i1 vector. The case I worry looks at least no drop. Can I disable for the vector in this patch?

spatel added inline comments.Jan 20 2023, 11:46 AM
llvm/test/Transforms/InstCombine/xor-and-or.ll
200

I don't think that's necessary. These kind of patterns are not likely in real vector code - we would have compares generating the condition vectors, and we would not have illegal types.

If someone finds a regression from this patch, we can fix it in the backend or limit the transform here.

This revision was landed with ongoing or failed builds.Feb 3 2023, 1:12 AM
This revision was automatically updated to reflect the committed changes.