[llvm] [InstSimplify] Fold `X * C >= X` to `true` (PR #129352)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 1 08:16:45 PST 2025


================
@@ -216,3 +216,132 @@ define i1 @lshr_add_ule_non_monotonic(i32 %x, i32 %y, i32 %z) {
   %cmp = icmp ule i32 %op1, %op2
   ret i1 %cmp
 }
+
+define i1 @mul_nuw_nonzero_rhs_monotonic(i8 %x, i8 %c) {
+; CHECK-LABEL: define i1 @mul_nuw_nonzero_rhs_monotonic(
+; CHECK-SAME: i8 [[X:%.*]], i8 [[C:%.*]]) {
+; CHECK-NEXT:    [[C_NONZERO:%.*]] = icmp ne i8 [[C]], 0
+; CHECK-NEXT:    call void @llvm.assume(i1 [[C_NONZERO]])
+; CHECK-NEXT:    ret i1 true
+;
+  %c_nonzero = icmp ne i8 %c, 0
+  call void @llvm.assume(i1 %c_nonzero)
+
+  %prod = mul nuw i8 %x, %c
----------------
veera-sivarajan wrote:

Added test for commuted pattern. Thank you.

https://github.com/llvm/llvm-project/pull/129352


More information about the llvm-commits mailing list