This is an archive of the discontinued LLVM Phabricator instance.

[mlir][index] Fold `cmp(max/min(x, cstA), cstB)`
ClosedPublic

Authored by Mogball on Jun 25 2023, 5:51 PM.

Details

Summary

This is a case that is not picked up by integer range inference and
suggests a weakness with integer range inference on the index dialect.
The problem is that when [1, SMAX_64] is truncated to 32 bits, the
resulting range could be [SMIN_32, SMAX_32], making the subsequent
comparison worthless. This is because integer range inference doesn't
know that the result of the max/min inference also changes based on the
bitwidth, and doing the truncation locally at the input of the
comparison op loses that information.

This also was a pattern that frequently showed up in our code, so adding
it as a folder allows dead code to be pruned more frequently.

Depends on D153731

Diff Detail

Event Timeline

Mogball created this revision.Jun 25 2023, 5:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 25 2023, 5:51 PM
Mogball requested review of this revision.Jun 25 2023, 5:51 PM
Mogball updated this revision to Diff 534393.Jun 25 2023, 6:06 PM

isa_and_nonnull so it doesn't crash

Mogball updated this revision to Diff 534395.Jun 25 2023, 6:15 PM

remove unneeded matchPattern

rriddle accepted this revision.Jun 26 2023, 11:46 AM
rriddle added inline comments.
mlir/lib/Dialect/Index/IR/IndexOps.cpp
470–472

This formatting hurts me.

This revision is now accepted and ready to land.Jun 26 2023, 11:46 AM
This revision was automatically updated to reflect the committed changes.