This is an archive of the discontinued LLVM Phabricator instance.

[IR] Remove the opcode argument from CmpInst::Create
AbandonedPublic

Authored by craig.topper on Jul 6 2017, 12:15 AM.

Details

Summary

The predicate argument alone should be enough to determine the class that needs to be created.

For some cases where we were always creating an ICmpInst I used the ICmpInst constructor directly. I can do that as a separate patch if that's prefered.

Do I need to be concerned with out of tree users of this?

Not sure who the best reviewers of this are. The CmpInst::Create function has been untouched for many years.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 6 2017, 12:15 AM
davide edited edge metadata.Jul 7 2017, 9:27 AM

This is correct, but why?

I think part of another change snuck into this patch. Particularly the stuff in InstCombineSelect.cpp. So ignore that.

I originally noticed this while playing around with removing the one use restriction from this code in visitXor

// not (cmp A, B) = !cmp A, B
CmpInst::Predicate Pred;
if (match(&I, m_Not(m_OneUse(m_Cmp(Pred, m_Value(), m_Value()))))) {
  cast<CmpInst>(Op0)->setPredicate(CmpInst::getInversePredicate(Pred));
  return replaceInstUsesWith(I, Op0);
}

This requires creating a new instruction and we should be able to use CmpInst::Create, but the m_Cmp matcher only returns the Predicate. So we have to examine the predicate to get the correct opcode.

craig.topper abandoned this revision.Oct 31 2017, 8:36 PM