This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold] allow folding icmp of null and constexpr
ClosedPublic

Authored by spatel on Mar 7 2021, 12:22 PM.

Details

Summary

I noticed that we were not folding expressions like this:
icmp ult (constexpr), null
in https://llvm.org/PR49355, so we end up with extremely large icmp instructions as the constant expressions pile up on each other.

Unless I am misunderstanding, there is no potential to mis-fold an unsigned boundary condition with a zero/null, so this is just a falling through a crack in the pattern matching.

The more general case of comparisons of non-zero constants and constexpr are more tricky and may require the datalayout to know how to cast to different types, etc.

Diff Detail

Event Timeline

spatel created this revision.Mar 7 2021, 12:22 PM
spatel requested review of this revision.Mar 7 2021, 12:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2021, 12:22 PM
spatel added inline comments.Mar 7 2021, 12:26 PM
llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
133

I missed updating this comment and/or add a test - will do that if we agree that the patch is correct.

nikic accepted this revision.Mar 7 2021, 12:33 PM

LGTM

This revision is now accepted and ready to land.Mar 7 2021, 12:33 PM
lebedev.ri accepted this revision.Mar 7 2021, 12:49 PM

I think this is fine.

llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
3

I think it would be good to test other inequality comparison opcodes too, if only as negative tests.

spatel marked an inline comment as done.Mar 8 2021, 6:07 AM