diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-26 15:32:54 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-26 15:32:54 +0000 |
commit | 2b7e31095d3fee45331df9f953c8a27c32a6a682 (patch) | |
tree | 08bee9063476878c23a593c83cd45e8ae21113ae /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | c307b00348467edfc3a84699f05fc89af40e899a (diff) | |
download | bcm5719-llvm-2b7e31095d3fee45331df9f953c8a27c32a6a682.tar.gz bcm5719-llvm-2b7e31095d3fee45331df9f953c8a27c32a6a682.zip |
[InstSimplify] fold srem with sext bool divisor
llvm-svn: 335616
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
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); } |