This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Arith] Add constant folder for left shift
ClosedPublic

Authored by wsmoses on Feb 28 2022, 6:58 AM.

Details

Summary

Add constant folder for left shift

Diff Detail

Event Timeline

wsmoses created this revision.Feb 28 2022, 6:58 AM
wsmoses requested review of this revision.Feb 28 2022, 6:58 AM

The test failures look real.

rriddle added inline comments.Feb 28 2022, 3:40 PM
mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
1859

We should likely check here that the shift is valid before trying to fold.

wsmoses added inline comments.Feb 28 2022, 3:46 PM
mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
1859

Valid in what sense? Doesn't ShLIOp have the semantic of other left shifts that top bits shifted off are discarded?

rriddle added inline comments.Mar 1 2022, 11:48 AM
mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
1859

I assume (though it isn't documented) that the behavior is similar to LLVM in that shifting by amounts larger than the integer width is undefined: https://llvm.org/docs/LangRef.html#id150

There are also questions about wrapping behavior, but we don't model those things at this point.

wsmoses updated this revision to Diff 412324.Mar 1 2022, 10:33 PM

Only handle shifts within width

Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 10:33 PM
ftynse accepted this revision.Mar 2 2022, 8:56 AM
This revision is now accepted and ready to land.Mar 2 2022, 8:56 AM
This revision was automatically updated to reflect the committed changes.