diff options
author | Sanjay Patel <spatel@rotateright.com> | 2021-08-10 10:41:23 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2021-08-10 10:43:07 -0400 |
commit | f43859b4370f978d2bc625643ccbe03775b99713 (patch) | |
tree | c43e7a9f66c934aa5b5ac52dcec73eee1cf43956 /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | 9b942a545cb53d4bae2071a2dea513be74f68221 (diff) | |
download | llvm-f43859b4370f978d2bc625643ccbe03775b99713.zip llvm-f43859b4370f978d2bc625643ccbe03775b99713.tar.gz llvm-f43859b4370f978d2bc625643ccbe03775b99713.tar.bz2 |
[InstSimplify] fold min/max with limit constant; NFC
This is already done within InstCombine:
https://alive2.llvm.org/ce/z/MiGE22
...but leaving it out of analysis makes it
harder to avoid infinite loops there.
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4cb3fdb..42e4433 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4080,6 +4080,22 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, std::swap(TrueVal, FalseVal); } + // Check for integer min/max with a limit constant: + // X > MIN_INT ? X : MIN_INT --> X + // X < MAX_INT ? X : MAX_INT --> X + if (TrueVal->getType()->isIntOrIntVectorTy()) { + Value *X, *Y; + SelectPatternFlavor SPF = + matchDecomposedSelectPattern(cast<ICmpInst>(CondVal), TrueVal, FalseVal, + X, Y).Flavor; + if (SelectPatternResult::isMinOrMax(SPF) && Pred == getMinMaxPred(SPF)) { + APInt LimitC = getMinMaxLimit(getInverseMinMaxFlavor(SPF), + X->getType()->getScalarSizeInBits()); + if (match(Y, m_SpecificInt(LimitC))) + return X; + } + } + if (Pred == ICmpInst::ICMP_EQ && match(CmpRHS, m_Zero())) { Value *X; const APInt *Y; |