[llvm] 9bdb918 - [InstCombine][NFC] Factor out constant check
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 04:55:42 PDT 2020
Author: Max Kazantsev
Date: 2020-06-04T18:54:23+07:00
New Revision: 9bdb91889020b3e61cba26adb1b9c64a24c09f95
URL: https://github.com/llvm/llvm-project/commit/9bdb91889020b3e61cba26adb1b9c64a24c09f95
DIFF: https://github.com/llvm/llvm-project/commit/9bdb91889020b3e61cba26adb1b9c64a24c09f95.diff
LOG: [InstCombine][NFC] Factor out constant check
We plan to add more transforms here. Besides, this check should be
done in the beginning just from function's name.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 48375a1a323f..e7371d28c745 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1432,6 +1432,13 @@ Instruction *InstCombiner::foldICmpWithZero(ICmpInst &Cmp) {
/// possible that code has been made unnecessary - do we canonicalize IR to
/// overflow/saturating intrinsics or not?).
Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) {
+ Value *Op0 = Cmp.getOperand(0), *Op1 = Cmp.getOperand(1);
+ ConstantInt *CI;
+
+ // Make sure that the RHS operand is a constant.
+ if (!match(Op1, m_ConstantInt(CI)))
+ return nullptr;
+
// Match the following pattern, which is a common idiom when writing
// overflow-safe integer arithmetic functions. The source performs an addition
// in wider type and explicitly checks for overflow using comparisons against
@@ -1444,10 +1451,9 @@ Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) {
// sum = a + b
// if (sum+128 >u 255) ... -> llvm.sadd.with.overflow.i8
CmpInst::Predicate Pred = Cmp.getPredicate();
- Value *Op0 = Cmp.getOperand(0), *Op1 = Cmp.getOperand(1);
Value *A, *B;
- ConstantInt *CI, *CI2; // I = icmp ugt (add (add A, B), CI2), CI
- if (Pred == ICmpInst::ICMP_UGT && match(Op1, m_ConstantInt(CI)) &&
+ ConstantInt *CI2; // I = icmp ugt (add (add A, B), CI2), CI
+ if (Pred == ICmpInst::ICMP_UGT &&
match(Op0, m_Add(m_Add(m_Value(A), m_Value(B)), m_ConstantInt(CI2))))
if (Instruction *Res = processUGT_ADDCST_ADD(Cmp, A, B, CI2, CI, *this))
return Res;
More information about the llvm-commits
mailing list