This patch introduces folding of and-reduce idiom and generates code
that is easier to read and which is lest costly in terms of icmp operations.
The folding is
icmp eq (bitcast(icmp ne (lhs, rhs)), 0)
into
icmp eq(bitcast(lhs), bitcast(rhs))
Differential D118317
[InstCombine] Fold and-reduce idiom mkazantsev on Jan 26 2022, 10:52 PM. Authored by
Details This patch introduces folding of and-reduce idiom and generates code icmp eq (bitcast(icmp ne (lhs, rhs)), 0) into icmp eq(bitcast(lhs), bitcast(rhs))
Diff Detail
Event TimelineComment Actions This should partly (on IR level) address https://github.com/llvm/llvm-project/issues/53419 Comment Actions TBH I'm not sure about converting legal vector types (e.g. <8 x i64>) into massive integer (i512). Comment Actions You're right, need to check if the new scalar type is a legal type. I'll add DL & negative tests & rebase on top. Thanks! This comment was removed by lebedev.ri. Comment Actions Added DL check that we only produce legal scalar types & rebased on top of new (negative) tests. Comment Actions I think it would make most sense to do at backend level, but i suppose it would be fine to do it here too.
Comment Actions Addressed Roman's comments:
Comment Actions NFC: replaced m_Constant with m_Zero as it seems that it'll be enough for all planned patterns. Comment Actions LGTM - if you don't plan to extend the predicate match to isEquality soon, please put a TODO comment on it.
Comment Actions I'll extend the predicate in the follow-up later today, thanks!
Comment Actions This is causing asserts to fire in Chromium builds. See https://bugs.chromium.org/p/chromium/issues/detail?id=1291929#c2 for a reproducer. I've reverted back to green in fabaca10b86f77f7d2d34db91fa6b284da924395 until it can be fixed. Comment Actions I didn't look at the crasher, but in hindsight, it seems clear that we need to check the bitcast source types more thoroughly. define i1 @eq_cast_eq-1(<2 x i4*> %x, <2 x i4*> %y) { %ic = icmp eq <2 x i4*> %x, %y %b = bitcast <2 x i1> %ic to i2 %r = icmp eq i2 %b, -1 ret i1 %r } |
Add a comment explaining what this does?