1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv32 %s \
3 ; RUN: | FileCheck --check-prefixes=CHECK,NOZBS %s
4 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv32 -mattr=+zbs %s \
5 ; RUN: | FileCheck --check-prefixes=CHECK,ZBS %s
6 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv64 %s \
7 ; RUN: | FileCheck --check-prefixes=CHECK,NOZBS %s
8 ; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=riscv64 -mattr=zbs %s \
9 ; RUN: | FileCheck --check-prefixes=CHECK,ZBS %s
11 @A = global i32 zeroinitializer
13 ; And should be sunk when Zbs is present and the mask doesn't fit in ANDI's
15 define i32 @and_sink1(i32 %a, i1 %c) {
16 ; NOZBS-LABEL: @and_sink1(
17 ; NOZBS-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], 2048
18 ; NOZBS-NEXT: br label [[BB0:%.*]]
20 ; NOZBS-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
21 ; NOZBS-NEXT: store i32 0, ptr @A, align 4
22 ; NOZBS-NEXT: br i1 [[CMP]], label [[BB0]], label [[BB2:%.*]]
24 ; NOZBS-NEXT: ret i32 0
26 ; ZBS-LABEL: @and_sink1(
27 ; ZBS-NEXT: br label [[BB0:%.*]]
29 ; ZBS-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 2048
30 ; ZBS-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 0
31 ; ZBS-NEXT: store i32 0, ptr @A, align 4
32 ; ZBS-NEXT: br i1 [[CMP]], label [[BB0]], label [[BB2:%.*]]
36 %and = and i32 %a, 2048
39 %cmp = icmp eq i32 %and, 0
41 br i1 %cmp, label %bb0, label %bb2
46 ; Don't sink when the mask has more than 1 bit set.
47 define i32 @and_sink2(i32 %a) {
48 ; CHECK-LABEL: @and_sink2(
49 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], 2049
50 ; CHECK-NEXT: br label [[BB0:%.*]]
52 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
53 ; CHECK-NEXT: store i32 0, ptr @A, align 4
54 ; CHECK-NEXT: br i1 [[CMP]], label [[BB0]], label [[BB2:%.*]]
56 ; CHECK-NEXT: ret i32 0
58 %and = and i32 %a, 2049
61 %cmp = icmp eq i32 %and, 0
63 br i1 %cmp, label %bb0, label %bb2
68 ; Don't sink when the mask fits in ANDI's immediate.
69 define i32 @and_sink3(i32 %a) {
70 ; CHECK-LABEL: @and_sink3(
71 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], 1024
72 ; CHECK-NEXT: br label [[BB0:%.*]]
74 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
75 ; CHECK-NEXT: store i32 0, ptr @A, align 4
76 ; CHECK-NEXT: br i1 [[CMP]], label [[BB0]], label [[BB2:%.*]]
78 ; CHECK-NEXT: ret i32 0
80 %and = and i32 %a, 1024
83 %cmp = icmp eq i32 %and, 0
85 br i1 %cmp, label %bb0, label %bb2