This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] visitTrunc - pass through undefs for trunc(shift(trunc/ext(x),c)) patterns
ClosedPublic

Authored by RKSimon on Oct 1 2020, 11:15 AM.

Details

Summary

Based on the recent patches D88475 and D88429 where we losing undef values due to extension/comparisons.

I've added a Constant::mergeUndefsWith method that merges the undef scalar/elements from another Constant into a specific Constant.

Diff Detail

Event Timeline

RKSimon created this revision.Oct 1 2020, 11:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2020, 11:15 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
RKSimon requested review of this revision.Oct 1 2020, 11:15 AM

Instead of eventually potentially duplicating the entirety of ConstantExpr methods,
i wonder if we can get away with an inverse of Constant::replaceUndefsWith(),
that takes two constants, and does an element-wise or'ing of undefs,
i.e. the LHS constant gets all the additional undefs that the RHS constant has.

RKSimon updated this revision to Diff 297832.Oct 13 2020, 5:38 AM
RKSimon edited the summary of this revision. (Show Details)

Reworked with a Constant::mergeUndefsWith helper as suggested by @lebedev.ri

lebedev.ri accepted this revision.Oct 13 2020, 5:49 AM

Perfect, LGTM.

llvm/include/llvm/IR/Constant.h
208

I'm having trouble parsing the first line.
I guess it talks about vector element undefs and scalar undefs, but it's hard go get that.

llvm/lib/IR/Constants.cpp
743

Nit: drop braces

763–766

You probably want

if (!match(NewC[I], m_Undef()) && match(OtherEltC, m_Undef())) {
  NewC[I] = OtherEltC;
  FoundExtraUndef = true;
}

otherwise you set FoundExtraUndef even if LHS already was undef.

This revision is now accepted and ready to land.Oct 13 2020, 5:49 AM
This revision was landed with ongoing or failed builds.Oct 13 2020, 6:57 AM
This revision was automatically updated to reflect the committed changes.