Skip to content

Commit e397a46

Browse files
committed
[InstSimplify] Precommit test for PR71528
1 parent 135d6f3 commit e397a46

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
3+
4+
;; The and X, (add Y, -1) pattern is from an earlier instcombine pass which
5+
;; converted
6+
7+
;; define i64 @f1() #0 {
8+
;; entry:
9+
;; %0 = call i64 @llvm.aarch64.sve.cntb(i32 31)
10+
;; %1 = call i64 @llvm.aarch64.sve.cnth(i32 31)
11+
;; %rem = urem i64 %0, %1
12+
;; ret i64 %rem
13+
;; }
14+
15+
;; into
16+
17+
;; define i64 @f1() #0 {
18+
;; entry:
19+
;; %0 = call i64 @llvm.vscale.i64()
20+
;; %1 = shl nuw nsw i64 %0, 4
21+
;; %2 = call i64 @llvm.vscale.i64()
22+
;; %3 = shl nuw nsw i64 %2, 3
23+
;; %4 = add nsw i64 %3, -1
24+
;; %rem = and i64 %1, %4
25+
;; ret i64 %rem
26+
;; }
27+
28+
;; InstCombine would have folded the original to returning 0 if the vscale
29+
;; calls were the same Value*, but since there's two of them it doesn't
30+
;; work and we convert the urem to add/and. CSE then gets rid of the extra
31+
;; vscale, leaving us with a new pattern to match. This only works because
32+
;; vscale is known to be a nonzero power of 2 (assuming there's a defined
33+
;; range for it).
34+
35+
define i64 @f1() #0 {
36+
; CHECK-LABEL: define i64 @f1
37+
; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
38+
; CHECK-NEXT: entry:
39+
; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
40+
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i64 [[TMP0]], 4
41+
; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i64 [[TMP0]], 3
42+
; CHECK-NEXT: [[TMP3:%.*]] = add nsw i64 [[TMP2]], -1
43+
; CHECK-NEXT: [[REM:%.*]] = and i64 [[TMP1]], [[TMP3]]
44+
; CHECK-NEXT: ret i64 [[REM]]
45+
;
46+
entry:
47+
%0 = call i64 @llvm.vscale.i64()
48+
%1 = shl nuw nsw i64 %0, 4
49+
%2 = shl nuw nsw i64 %0, 3
50+
%3 = add nsw i64 %2, -1
51+
%rem = and i64 %1, %3
52+
ret i64 %rem
53+
}
54+
55+
declare i64 @llvm.vscale.i64()
56+
57+
attributes #0 = { vscale_range(1,16) }

0 commit comments

Comments
 (0)