llvm.org GIT mirror llvm / d8d1584
The sign of an srem instruction is the sign of its dividend (the first argument), regardless of the divisor. Teach instcombine about this and fix test7 in PR9343! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126635 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 8 years ago
2 changed file(s) with 23 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
13391339 }
13401340 }
13411341 break;
1342
1343 case Instruction::SRem: {
1344 bool TrueIfSigned;
1345 if (LHSI->hasOneUse() &&
1346 isSignBitCheck(ICI.getPredicate(), RHS, TrueIfSigned)) {
1347 // srem has the same sign as its dividend so the divisor is irrelevant.
1348 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0), RHS);
1349 }
1350 break;
1351 }
13421352 }
13431353
13441354 // Simplify icmp_eq and icmp_ne instructions with integer constant RHS.
18541864 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
18551865 ConstantInt::get(CI->getContext(), CI->getValue()+1));
18561866 case ICmpInst::ICMP_UGE:
1857 assert(!CI->isMinValue(false)); // A >=u MIN -> TRUE
1867 assert(!CI->isMinValue(false)); // A >=u MIN -> TRUE
18581868 return new ICmpInst(ICmpInst::ICMP_UGT, Op0,
18591869 ConstantInt::get(CI->getContext(), CI->getValue()-1));
18601870 case ICmpInst::ICMP_SGE:
1861 assert(!CI->isMinValue(true)); // A >=s MIN -> TRUE
1871 assert(!CI->isMinValue(true)); // A >=s MIN -> TRUE
18621872 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
18631873 ConstantInt::get(CI->getContext(), CI->getValue()-1));
18641874 }
19121922 ConstantInt::get(I.getContext(), Op1Min));
19131923
19141924 // Based on the range information we know about the LHS, see if we can
1915 // simplify this comparison. For example, (x&4) < 8 is always true.
1925 // simplify this comparison. For example, (x&4) < 8 is always true.
19161926 switch (I.getPredicate()) {
19171927 default: llvm_unreachable("Unknown icmp opcode!");
19181928 case ICmpInst::ICMP_EQ: {
376376 %c = icmp ugt i32 %lhs, %rhs
377377 ret i1 %c
378378 }
379
380 ; PR9343 #7
381 ; CHECK: @test39
382 ; CHECK: ret i1 false
383 define i1 @test39(i31 %X, i32 %Y) {
384 %A = zext i31 %X to i32
385 %B = srem i32 %A, %Y
386 %C = icmp slt i32 %B, 0
387 ret i1 %C
388 }