This is an archive of the discontinued LLVM Phabricator instance.

SelectionDAG: Select min/max when both are used
ClosedPublic

Authored by arsenm on May 12 2016, 6:47 PM.

Details

Summary

Allow two users of the condition if the other user
is also a min/max select. i.e.

%c = icmp slt i32 %x, %y
%min = select i1 %c, i32 %x, i32 %y
%max = select i1 %c, i32 %y, i32 %x

Diff Detail

Event Timeline

arsenm updated this revision to Diff 57126.May 12 2016, 6:47 PM
arsenm retitled this revision from to SelectionDAG: Select min/max when both are used.
arsenm updated this object.
arsenm added a reviewer: jmolloy.
arsenm added a subscriber: llvm-commits.
jmolloy accepted this revision.May 13 2016, 1:15 AM
jmolloy edited edge metadata.

Hi,

Generally looks fine as-is, but I think the helper can be simplified a bit.

James

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
2702

I think this can be written simpler. Is it important that we bail out for > 2 users? If we have > 2 users of an icmp that are both selects, surely one would have been CSEd before now?

So we could just do:

static bool hasOnlySelectUsers(Value *Cond) {
  return std::all_of(Cond->user_begin(), Cond->user_end(), [](Value *V) {
    return isa<SelectInst>(V);
  });
}

?

This revision is now accepted and ready to land.May 13 2016, 1:15 AM
junbuml added inline comments.May 13 2016, 5:31 AM
test/CodeGen/AMDGPU/select-i1.ll
16

You need to add your check.

arsenm added inline comments.May 13 2016, 7:06 PM
test/CodeGen/AMDGPU/select-i1.ll
16

This won't actually be hit because min/max isn't legal for i1

arsenm closed this revision.May 16 2016, 2:04 PM

r269699