This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] peek through 2-input shuffles in ComputeNumSignBits
ClosedPublic

Authored by spatel on Nov 1 2018, 10:46 AM.

Details

Summary

This patch gives the IR ComputeNumSignBits the same functionality as the DAG version (the code is derived from the existing code).

This an extension of the single input shuffle analysis added with D53659.

Diff Detail

Event Timeline

spatel created this revision.Nov 1 2018, 10:46 AM
RKSimon added inline comments.Nov 2 2018, 3:48 AM
lib/Analysis/ValueTracking.cpp
2526

Don't you still have to check if a valid shuffle mask element references an UNDEF operand?

%1 = shufflevector <4 x float> %a0, <4 x float> undef, <4 x i32> <i32 4, i32 5, i32 0, i32 1>

Or is that guaranteed to have already been handled, the mask element set to undef and caught by containsUndefElement() ?

spatel added inline comments.Nov 2 2018, 8:05 AM
lib/Analysis/ValueTracking.cpp
2526

Yes, good catch. This is an analysis usable by any pass, so we can't assume canonical code. That means even the existing assert for 2 undefs is not allowed; it has to be a real check.

RKSimon added inline comments.Nov 2 2018, 9:18 AM
lib/Analysis/ValueTracking.cpp
2526

You can probably go further and replicate the SelectionDAG version's checking of the entire mask - bailing on undef mask elts and determining if it demands/references LHS/RHS operands - and then calling the LHS/RHS num sign bits accordingly.

Might be good prep work for PR36319.

spatel updated this revision to Diff 172408.Nov 2 2018, 11:32 AM

Patch updated:
Copy the DAG logic completely to make sure undefs are handled properly and allow further enhancements.
I added a unit-test to show that the existing code had a bug.
Also, I fixed the 2-undef bug and added a unit-test with:
rL345988

RKSimon accepted this revision.Nov 2 2018, 11:54 AM

LGTM - thanks

This revision is now accepted and ready to land.Nov 2 2018, 11:54 AM
This revision was automatically updated to reflect the committed changes.