optimized with "clang -emit-llvm-bc | opt -std-compile-opts".
//===---------------------------------------------------------------------===//
+
+We would like to do the following transform in the instcombiner:
+
+ -X/C -> X/-C
+
+However, this isn't valid if (-X) overflows. We can implement this when we
+have the concept of a "C signed subtraction" operator that which is undefined
+on overflow.
+
+//===---------------------------------------------------------------------===//
// sdiv X, -1 == -X
if (RHS->isAllOnesValue())
return BinaryOperator::CreateNeg(Op0);
-
- // -X/C -> X/-C, if and only if negation doesn't overflow.
- if (Value *LHSNeg = dyn_castNegVal(Op0)) {
- if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) {
- Constant *RHSNeg = ConstantExpr::getNeg(RHS);
- if (RHS != RHSNeg) { // Check that there is no overflow.
- Constant *CINeg = ConstantExpr::getNeg(CI);
- if (CI != CINeg) // Check that there is no overflow.
- return BinaryOperator::CreateSDiv(LHSNeg, RHSNeg);
- }
- }
- }
}
// If the sign bits of both operands are zero (i.e. we can prove they are