Page MenuHomePhabricator

Update m_Undef to match vectors/aggrs with undefs and poisons mixed
ClosedPublic

Authored by aqjune on Apr 8 2021, 9:09 AM.

Details

Summary

This is an alternative approach to fixing https://reviews.llvm.org/D93990#2666922
by teaching m_Undef to match vectors/aggrs with poison elements instead of hard-coding
it at SimplifyQuery::isUndefValue (D99853).

This patch also contains fixes in InstCombine files to use the m_Undef matcher instead
of isa<UndefValue>.

Diff Detail

Event Timeline

aqjune created this revision.Apr 8 2021, 9:09 AM
aqjune requested review of this revision.Apr 8 2021, 9:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2021, 9:09 AM
aqjune added inline comments.Apr 8 2021, 9:12 AM
llvm/test/Transforms/PhaseOrdering/X86/scalarization.ll
30 ↗(On Diff #336143)

Interestingly, this updates caused unused lanes to be undef even if they were updated to be poison in the past.
I guess this is related to the (still) ongoing work about shufflevector's undef mask things.
The work is currently blocked by the incorrect select -> and/or transformation.
If the shufflevector patches are finally landed, this will be resolved.

lebedev.ri added inline comments.Apr 17 2021, 12:39 AM
llvm/include/llvm/IR/PatternMatch.h
92–100

I'm not sure i like recursion here.
How about a worklist algorithm?

aqjune updated this revision to Diff 338292.Apr 17 2021, 4:10 AM

Use Worklist

aqjune marked an inline comment as done.Apr 17 2021, 4:11 AM
aqjune added inline comments.
llvm/include/llvm/IR/PatternMatch.h
92–100

Thank you for the suggestion! I updated this patch.

lebedev.ri added inline comments.Apr 17 2021, 4:19 AM
llvm/include/llvm/IR/PatternMatch.h
92–100

The point of that lambda was to check non-aggregate operands on the spot, without adding them into the worklist.
If we don't want that, just inline the lambda into the loop,
and do plain Worklist.emplace_back(V); before the loop..

aqjune updated this revision to Diff 338295.Apr 17 2021, 4:54 AM
aqjune marked an inline comment as done.

Avoid adding elem to Worklist, clang-format

aqjune added inline comments.Apr 17 2021, 4:55 AM
llvm/include/llvm/IR/PatternMatch.h
92–100

Would this new version address the concern, maybe?

last few nits

llvm/include/llvm/IR/PatternMatch.h
111–112

no else after return

131–132

I think this should state what happens about partial cases,
i.e. is { undef, 0 } an undef? I guess not, it should not match.

aqjune updated this revision to Diff 338296.Apr 17 2021, 5:38 AM

Clarify when an aggregate with non-undef/poison elements is given, address comments, add more unit tests

aqjune marked 2 inline comments as done.Apr 17 2021, 5:38 AM
lebedev.ri added inline comments.Apr 17 2021, 5:47 AM
llvm/include/llvm/IR/PatternMatch.h
103

Sorry for being nitpicky, but is that what it returns?
Wouldn't it have to then return false for e.g. constant expressions, since they could be undef?

aqjune updated this revision to Diff 338298.Apr 17 2021, 6:02 AM

Be more explicit about what CheckValue returns

aqjune marked an inline comment as done.Apr 17 2021, 6:02 AM
lebedev.ri accepted this revision.Apr 17 2021, 6:07 AM

LGTM.
Please split this patch into two - the matcher+unittest, and the usage of the matcher.

llvm/include/llvm/IR/PatternMatch.h
121–122

Hm, i'd invert the CheckValue()'s return value, this seems unnatural.

This revision is now accepted and ready to land.Apr 17 2021, 6:07 AM
aqjune marked an inline comment as done.Sat, Apr 17, 7:11 PM
This revision was landed with ongoing or failed builds.Sat, Apr 17, 7:11 PM
This revision was automatically updated to reflect the committed changes.