From 2b7e31095d3fee45331df9f953c8a27c32a6a682 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 26 Jun 2018 15:32:54 +0000 Subject: [InstSimplify] fold srem with sext bool divisor llvm-svn: 335616 --- llvm/lib/Analysis/InstructionSimplify.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4f5bed91dcc..4a80558dd1b 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1099,6 +1099,12 @@ Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) { /// If not, this returns null. static Value *SimplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse) { + // If the divisor is 0, the result is undefined, so assume the divisor is -1. + // srem Op0, (sext i1 X) --> srem Op0, -1 --> 0 + Value *X; + if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) + return ConstantInt::getNullValue(Op0->getType()); + return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse); } -- cgit v1.2.3