This is an archive of the discontinued LLVM Phabricator instance.

[ConstraintElimination] Fix undefined behaviour in shl decomposition
ClosedPublic

Authored by zjaffal on Mar 9 2023, 3:03 AM.

Details

Summary

Add checks to prevent decomposing constants bigger than 64.
relates to https://github.com/llvm/llvm-project/issues/61127

Diff Detail

Event Timeline

zjaffal created this revision.Mar 9 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 3:03 AM
zjaffal requested review of this revision.Mar 9 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 3:03 AM
fhahn accepted this revision.Mar 9 2023, 7:48 AM

LGTM. thanks! But please include the full test (from D145676) in the commit with the fix, as the tests will otherwise fail on the UBSan bots.

This revision is now accepted and ready to land.Mar 9 2023, 7:48 AM
zjaffal updated this revision to Diff 503784.Mar 9 2023, 8:20 AM

Add the tests from from D145676 herew

This revision was landed with ongoing or failed builds.Mar 9 2023, 10:21 AM
This revision was automatically updated to reflect the committed changes.

This change appears to have broken the Windows MLIR bot (I suspect others Windows builders).
https://lab.llvm.org/buildbot/#/builders/13/builds/32862/steps/6/logs/stdio

C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Scalar\ConstraintElimination.cpp(382): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Scalar\ConstraintElimination.cpp(382): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

This change appears to have broken the Windows MLIR bot (I suspect others Windows builders).
https://lab.llvm.org/buildbot/#/builders/13/builds/32862/steps/6/logs/stdio

C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Scalar\ConstraintElimination.cpp(382): error C2220: the following warning is treated as an error
C:\buildbot\mlir-x64-windows-ninja\llvm-project\llvm\lib\Transforms\Scalar\ConstraintElimination.cpp(382): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

UBSAN as well https://lab.llvm.org/buildbot/#/builders/238/builds/1810

fhahn added a comment.Mar 10 2023, 3:53 AM

Thanks for the fix @vitalybuka ! I am surprised this wasn't covered by the added tests. Any idea why that is?

Thanks for the fix @vitalybuka ! I am surprised this wasn't covered by the added tests. Any idea why that is?

I guess you need shift by [32; 63] to hit this case

Thanks for the fix @vitalybuka ! I am surprised this wasn't covered by the added tests. Any idea why that is?

I guess you need shift by [32; 63] to hit this case

Right, @zjaffal could you add a test case which shifts by an offset between [32; 63] ? Ideally one where ConstraintElimination can perform a simplification.