File: wrap-flags.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 (88 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (12)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=reassociate,dce -S | FileCheck %s
; PR12985

; Verify the nsw flags are preserved when converting shl to mul.

define i32 @shl_to_mul_nsw(i32 %i) {
;
; CHECK-LABEL: @shl_to_mul_nsw(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MUL:%.*]] = mul i32 [[I:%.*]], -2147483648
; CHECK-NEXT:    [[MUL2:%.*]] = add i32 [[MUL]], 1
; CHECK-NEXT:    ret i32 [[MUL2]]
;
entry:
  %mul = shl nsw i32 %i, 31
  %mul2 = add i32 %mul, 1
  ret i32 %mul2
}

define i32 @shl_to_mul_nsw_2(i32 %i) {
;
; CHECK-LABEL: @shl_to_mul_nsw_2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MUL:%.*]] = mul nsw i32 [[I:%.*]], 1073741824
; CHECK-NEXT:    [[MUL2:%.*]] = add i32 [[MUL]], 1
; CHECK-NEXT:    ret i32 [[MUL2]]
;
entry:
  %mul = shl nsw i32 %i, 30
  %mul2 = add i32 %mul, 1
  ret i32 %mul2
}

define i32 @shl_to_mul_nuw(i32 %i) {
;
; CHECK-LABEL: @shl_to_mul_nuw(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MUL:%.*]] = mul nuw i32 [[I:%.*]], 4
; CHECK-NEXT:    [[MUL2:%.*]] = add i32 [[MUL]], 1
; CHECK-NEXT:    ret i32 [[MUL2]]
;
entry:
  %mul = shl nuw i32 %i, 2
  %mul2 = add i32 %mul, 1
  ret i32 %mul2
}

define i32 @shl_to_mul_nuw_nsw(i32 %i) {
;
; CHECK-LABEL: @shl_to_mul_nuw_nsw(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MUL:%.*]] = mul nuw nsw i32 [[I:%.*]], 4
; CHECK-NEXT:    [[MUL2:%.*]] = add i32 [[MUL]], 1
; CHECK-NEXT:    ret i32 [[MUL2]]
;
entry:
  %mul = shl nuw nsw i32 %i, 2
  %mul2 = add i32 %mul, 1
  ret i32 %mul2
}

define i32 @shl_to_mul_nuw_nsw_bitwidth_m1(i32 %i) {
;
; CHECK-LABEL: @shl_to_mul_nuw_nsw_bitwidth_m1(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MUL:%.*]] = mul nuw nsw i32 [[I:%.*]], -2147483648
; CHECK-NEXT:    [[MUL2:%.*]] = add i32 [[MUL]], 1
; CHECK-NEXT:    ret i32 [[MUL2]]
;
entry:
  %mul = shl nuw nsw i32 %i, 31
  %mul2 = add i32 %mul, 1
  ret i32 %mul2
}

define i2 @pr23926(i2 %X1, i2 %X2) {
;
; CHECK-LABEL: @pr23926(
; CHECK-NEXT:    [[X1_NEG:%.*]] = sub i2 0, [[X1:%.*]]
; CHECK-NEXT:    [[ADD_NEG:%.*]] = add i2 [[X1_NEG]], -1
; CHECK-NEXT:    [[SUB:%.*]] = add i2 [[ADD_NEG]], [[X2:%.*]]
; CHECK-NEXT:    ret i2 [[SUB]]
;
  %add = add nuw i2 %X1, 1
  %sub = sub nuw nsw i2 %X2, %add
  ret i2 %sub
}