This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fold (max/min X, X) -> X.
ClosedPublic

Authored by craig.topper on May 4 2022, 11:38 AM.

Details

Summary

This also shows we're missing zero_extend/sign_extend undef -> 0 fold in DAGCombiner.

Diff Detail

Event Timeline

craig.topper created this revision.May 4 2022, 11:38 AM
craig.topper requested review of this revision.May 4 2022, 11:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2022, 11:38 AM

Don't we need this in DAGCombine as well to handle cases where the same arg appears after another fold?

Don't we need this in DAGCombine as well to handle cases where the same arg appears after another fold?

Yes. I could also just move this to DAGCombine only and not affect pr55271.

Move to DAGCombine

Remove pr55271 test.

craig.topper retitled this revision from [SelectionDAG] Teach getNode to fold (max/min X, X) -> X. to [DAGCombiner] Fold (max/min X, X) -> X..May 4 2022, 11:54 PM
craig.topper edited the summary of this revision. (Show Details)
craig.topper edited the summary of this revision. (Show Details)
craig.topper added inline comments.May 4 2022, 11:56 PM
llvm/test/CodeGen/RISCV/min-max.ll
534

We wouldn't hit the bug if we folded sext/zext undef in DAGCombiner. Instead we type legalize and hit the sext_inreg getNode bug.

RKSimon accepted this revision.May 5 2022, 1:05 AM

LGTM

This revision is now accepted and ready to land.May 5 2022, 1:05 AM
This revision was landed with ongoing or failed builds.May 5 2022, 9:40 AM
This revision was automatically updated to reflect the committed changes.