[llvm] Fold (a % b) lt/ge (b-1) where b is a power of 2 (PR #72504)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 14:29:59 PST 2023


elhewaty wrote:

@dtcxzyw why doesn't the code optimize the following test?

```
define i1 @srem_slt_test1(i64 %x, i64 %C) {
; CHECK-LABEL: @srem_slt_test1(
; CHECK-NEXT:    [[PRECOND:%.*]] = icmp sgt i64 [[C:%.*]], -1
; CHECK-NEXT:    call void @llvm.assume(i1 [[PRECOND]])
; CHECK-NEXT:    [[CMINUS1:%.*]] = add nsw i64 [[C]], -1
; CHECK-NEXT:    [[Y:%.*]] = srem i64 [[X:%.*]], [[C]]
; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i64 [[Y]], [[CMINUS1]]
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %precond = icmp sge i64 %C, 0
  call void @llvm.assume(i1 %precond)
  %Cminus1 = add i64 %C, -1
  %y = srem i64 %x, %C
  %cmp = icmp slt i64 %y, %Cminus1
  ret i1 %cmp
}
```

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


More information about the llvm-commits mailing list