[llvm] [SelectionDAG] optimize sdiv with positive divisor and positive magic (PR #189287)

Takashi Idobe via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 05:49:28 PDT 2026


================
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc64 < %s | FileCheck --check-prefix=CHECK %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc < %s | FileCheck --check-prefix=CHECK %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc64 < %s | FileCheck --check-prefix=CHECK-64 %s
----------------
Takashiidobe wrote:

I think you want `--check-prefixes=CHECK,CHECK-64` for this line and ` --check-prefixes=CHECK,CHECK-32` for the next line, correct, so only the differences show?

i.e. the checks coalesce when there's no difference between the targets

```llvm
; Don't fold if the divisor is one.
define i32 @dont_fold_srem_one(i32 %x) {
; CHECK-LABEL: dont_fold_srem_one:
; CHECK:       # %bb.0:
; CHECK-NEXT:    li 3, 0
; CHECK-NEXT:    blr
  %1 = srem i32 %x, 1
  ret i32 %1
}
```

and then for the only test that diverges it shows both:

```llvm
define i32 @fold_srem_positive_even(i32 %x) {
; CHECK-64-LABEL: fold_srem_positive_even:
; CHECK-64:       # %bb.0:
; CHECK-64-NEXT:    lis 4, 15827
; CHECK-64-NEXT:    srawi 5, 3, 31
; CHECK-64-NEXT:    ori 4, 4, 36849
; CHECK-64-NEXT:    mulhw 4, 3, 4
; CHECK-64-NEXT:    srawi 4, 4, 8
; CHECK-64-NEXT:    sub 4, 4, 5
; CHECK-64-NEXT:    mulli 4, 4, 1060
; CHECK-64-NEXT:    sub 3, 3, 4
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: fold_srem_positive_even:
; CHECK-32:       # %bb.0:
; CHECK-32-NEXT:    lis 4, 15827
; CHECK-32-NEXT:    ori 4, 4, 36849
; CHECK-32-NEXT:    mulhw 4, 3, 4
; CHECK-32-NEXT:    srawi 4, 4, 8
; CHECK-32-NEXT:    srawi 5, 3, 31
; CHECK-32-NEXT:    sub 4, 4, 5
; CHECK-32-NEXT:    mulli 4, 4, 1060
; CHECK-32-NEXT:    sub 3, 3, 4
; CHECK-32-NEXT:    blr
  %1 = srem i32 %x, 1060
  ret i32 %1
}
```

With only that line the CHECK-64 prefix will be unused.

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


More information about the llvm-commits mailing list