llvm-project/llvm/lib/Transforms/InstCombine
Craig Topper c22c7b1459 [InstCombine] Refactor SimplifyUsingDistributiveLaws to more explicitly skip code when LHS/RHS aren't BinaryOperators
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.

Differential Revision: https://reviews.llvm.org/D31913

llvm-svn: 300353
2017-04-14 17:55:41 +00:00
..
CMakeLists.txt [CMake] NFC. Updating CMake dependency specifications 2016-11-17 04:36:50 +00:00
InstCombineAddSub.cpp Fix spelling compliment->complement. Mostly refering to 2s complement. NFC 2017-04-11 18:47:58 +00:00
InstCombineAndOrXor.cpp [InstCombine] fold X == 0 || X == -1 to one compare (PR32524) 2017-04-13 18:47:06 +00:00
InstCombineCalls.cpp [IR] Make getParamAttributes take argument numbers, not ArgNo+1 2017-04-13 23:12:13 +00:00
InstCombineCasts.cpp InstCombine: Check source value precision when reducing cast intrinsic 2017-03-20 21:59:24 +00:00
InstCombineCompares.cpp [InstCombine] Use APInt::getBitsSetFrom instead of inverting the result of getLowBitsSet. NFC 2017-04-13 21:49:48 +00:00
InstCombineInternal.h [InstCombine] Move portion of SimplifyDemandedUseBits that deals with instructions with multiple uses out to a separate method. NFCI 2017-04-12 18:05:21 +00:00
InstCombineLoadStoreAlloca.cpp [InstCombine] Fix bug in pointer replacement 2017-02-24 20:27:25 +00:00
InstCombineMulDivRem.cpp [InstCombine] improve readability; NFCI 2017-03-14 17:27:27 +00:00
InstCombinePHI.cpp fix formatting; NFC 2017-01-31 17:25:42 +00:00
InstCombineSelect.cpp [InstCombine] fix wrong undef handling when converting select to shuffle 2017-04-12 18:39:53 +00:00
InstCombineShifts.cpp [InstCombine] allow (X * C2) << C1 --> X * (C2 << C1) for vectors 2017-02-09 23:13:04 +00:00
InstCombineSimplifyDemanded.cpp [InstCombine] Use APInt::setSignBit and APInt::isNegative(). NFC 2017-04-14 05:09:04 +00:00
InstCombineVectorOps.cpp InstCombine: Use the InstSimplify hook for shufflevector 2017-04-04 04:47:57 +00:00
InstructionCombining.cpp [InstCombine] Refactor SimplifyUsingDistributiveLaws to more explicitly skip code when LHS/RHS aren't BinaryOperators 2017-04-14 17:55:41 +00:00
LLVMBuild.txt