File: bypass-slow-div-constant-numerator.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (35 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' < %s | FileCheck %s

target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-cuda"

; When we bypass slow div with a constant numerator which fits into the bypass
; width, we still emit the bypass code, but we don't 'or' the numerator with
; the denominator.
; CHECK-LABEL: @small_constant_numer
define i64 @small_constant_numer(i64 %a) {
  ; CHECK: [[AND:%[0-9]+]] = and i64 %a, -4294967296
  ; CHECK: icmp eq i64 [[AND]], 0

  ; CHECK: [[TRUNC:%[0-9]+]] = trunc i64 %a to i32
  ; CHECK: udiv i32 -1, [[TRUNC]]
  %d = sdiv i64 4294967295, %a  ; 0xffff'ffff
  ret i64 %d
}

; When we try to bypass slow div with a constant numerator which *doesn't* fit
; into the bypass width, leave it as a plain 64-bit div with no bypass.
; CHECK-LABEL: @large_constant_numer
define i64 @large_constant_numer(i64 %a) {
  ; CHECK-NOT: udiv i32
  %d = sdiv i64 4294967296, %a  ; 0x1'0000'0000
  ret i64 %d
}

; For good measure, try a value larger than 2^32.
; CHECK-LABEL: @larger_constant_numer
define i64 @larger_constant_numer(i64 %a) {
  ; CHECK-NOT: udiv i32
  %d = sdiv i64 5000000000, %a
  ret i64 %d
}