if (Instruction *Common = commonIRemTransforms(I))
return Common;
- if (Value *RHSNeg = dyn_castNegVal(Op1))
- if (!isa<Constant>(RHSNeg) ||
- (isa<ConstantInt>(RHSNeg) &&
- cast<ConstantInt>(RHSNeg)->getValue().isStrictlyPositive())) {
- // X % -Y -> X % Y
+ {
+ const APInt *Y;
+ // X % -Y -> X % Y
+ if (match(Op1, m_APInt(Y)) && Y->isNegative() && !Y->isMinSignedValue()) {
Worklist.AddValue(I.getOperand(1));
- I.setOperand(1, RHSNeg);
+ I.setOperand(1, ConstantInt::get(I.getType(), -*Y));
return &I;
}
+ }
// If the sign bits of both operands are zero (i.e. we can prove they are
// unsigned inputs), turn this into a urem.
ret i1024 %D
}
-define i14 @test15(i14 %A, i14 %B) {
- %C = sub i14 0, %A ; <i14> [#uses=1]
- %D = srem i14 %B, %C ; <i14> [#uses=1]
- ret i14 %D
-}
-
define i51 @test16(i51 %A) {
%X = sdiv i51 %A, 1123 ; <i51> [#uses=1]
%Y = sub i51 0, %X ; <i51> [#uses=1]
%D = srem i32 %B, %C
ret i32 %D
; CHECK-LABEL: @test15(
-; CHECK: %D = srem i32 %B, %A
-; CHECK: ret i32 %D
+; CHECK: %[[sub:.*]] = sub i32 0, %A
+; CHECK-NEXT: %[[rem:.*]] = srem i32 %B, %[[sub]]
+; CHECK: ret i32 %[[rem]]
}
define i32 @test16(i32 %A) {