Page MenuHomePhabricator

[InstSimplify][ConstantFolding] Teach constant folding how to handle icmp null, (inttoptr x) as well as it handles icmp (inttoptr x), null
ClosedPublic

Authored by craig.topper on Jun 1 2017, 2:33 PM.

Details

Summary

The constant folding code currently assumes that the constant expression will always be on the left and the simple null will be on the right. But that's not true at least on the path from InstSimplify.

This patch adds support to ConstantFolding to detect the reversed case.

Diff Detail

Repository
rL LLVM

Event Timeline

davide edited edge metadata.Jun 1 2017, 2:41 PM

This is exactly the same transform, just with the operands commuted, isn't it? Is there a way to avoid the code duplication & share the two codepaths?
That would be great if we find a bug in one of them, so that we don't have to replicate the fix in the other.

Thanks!

Implement with no code duplication. Just detect that LHS is not a constant expr, but RHS is. If that's the case swap the predicate and the operands and recurse back into the same function.

joey accepted this revision.Jun 2 2017, 3:18 AM
joey added a subscriber: joey.

LGTM!

This revision is now accepted and ready to land.Jun 2 2017, 3:18 AM
This revision was automatically updated to reflect the committed changes.