[llvm] [InstCombine] Simplify fractions when there is no overflow (PR #92949)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 16:43:27 PDT 2024
================
@@ -1678,6 +1678,17 @@ define i32 @sdiv_sdiv_mul_nsw_exact_use(i32 %x, i32 %y, i32 %z) {
ret i32 %r
}
+define i32 @x_times_150_over_100(i32 %x) {
+; CHECK-LABEL: @x_times_150_over_100(
+; CHECK-NEXT: [[TMP1:%.*]] = mul nuw nsw i32 [[X:%.*]], 3
+; CHECK-NEXT: [[D1:%.*]] = lshr i32 [[TMP1]], 1
+; CHECK-NEXT: ret i32 [[D1]]
+;
+ %m = mul nuw nsw i32 %x, 150
----------------
topperc wrote:
Don't we need tests to cover all 3 cases here
```
if (IsSigned && C1->isNegative() && C2->isNegative()) {
NewC1 = C1->abs().udiv(GCD);
NewC2 = C2->abs().udiv(GCD);
} else if (IsSigned) {
NewC1 = C1->sdiv(GCD);
NewC2 = C2->sdiv(GCD);
} else {
NewC1 = C1->udiv(GCD);
NewC2 = C2->udiv(GCD);
}
```
https://github.com/llvm/llvm-project/pull/92949
More information about the llvm-commits
mailing list