This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Refactor SimplifyUsingDistributiveLaws to more explicitly skip code when LHS/RHS aren't BinaryOperators
ClosedPublic

Authored by craig.topper on Apr 10 2017, 5:14 PM.

Details

Summary

Currently this code always makes 2 or 3 calls to tryFactorization regardless of whether the LHS/RHS are BinaryOperators. We make 3 calls when both operands are BinaryOperators with the same opcode. Or surprisingly, when neither are BinaryOperators. This is because getBinOpsForFactorization returns Instruction::BinaryOpsEnd when the operand is not a BinaryOperator. If both LHS and RHS are not BinaryOperators then they both have an Opcode of Instruction::BinaryOpsEnd. When this happens we rely on tryFactorization to early out due to A/B/C/D being null. Similar behavior occurs for the other calls, we rely on getBinOpsForFactorization having made A/B or C/D null to get tryFactorization to early out.

We also rely on these null checks to check the result of getIdentityValue and early out for it.

This patches refactors this to pull these checks up to SimplifyUsingDistributiveLaws so we don't rely on BinaryOpsEnd as a sentinel or this A/B/C/D null behavior. I think this makes this code easier to reason about. Should also give a tiny performance improvement for cases where the LHS or RHS isn't a BinaryOperator.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 10 2017, 5:14 PM
spatel accepted this revision.Apr 14 2017, 8:20 AM

LGTM.

This revision is now accepted and ready to land.Apr 14 2017, 8:20 AM
davide accepted this revision.Apr 14 2017, 8:20 AM

LGTM

This revision was automatically updated to reflect the committed changes.