1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV64I
5 ; Make sure we don't generate an addi in the loop in
6 ; addition to the addiw. Previously we type legalize the
7 ; setcc use using signext and the phi use using anyext.
8 ; We now detect when it would be beneficial to replace
11 define void @quux(i32 signext %arg, i32 signext %arg1) nounwind {
13 ; RV64I: # %bb.0: # %bb
14 ; RV64I-NEXT: addi sp, sp, -32
15 ; RV64I-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
16 ; RV64I-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
17 ; RV64I-NEXT: sd s1, 8(sp) # 8-byte Folded Spill
18 ; RV64I-NEXT: beq a0, a1, .LBB0_3
19 ; RV64I-NEXT: # %bb.1: # %bb2.preheader
20 ; RV64I-NEXT: mv s0, a1
21 ; RV64I-NEXT: mv s1, a0
22 ; RV64I-NEXT: .LBB0_2: # %bb2
23 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
24 ; RV64I-NEXT: call hoge@plt
25 ; RV64I-NEXT: addiw s1, s1, 1
26 ; RV64I-NEXT: bne s1, s0, .LBB0_2
27 ; RV64I-NEXT: .LBB0_3: # %bb6
28 ; RV64I-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
29 ; RV64I-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
30 ; RV64I-NEXT: ld s1, 8(sp) # 8-byte Folded Reload
31 ; RV64I-NEXT: addi sp, sp, 32
34 %tmp = icmp eq i32 %arg, %arg1
35 br i1 %tmp, label %bb6, label %bb2
37 bb2: ; preds = %bb2, %bb
38 %tmp3 = phi i32 [ %tmp4, %bb2 ], [ %arg, %bb ]
39 tail call void @hoge()
40 %tmp4 = add nsw i32 %tmp3, 1
41 %tmp5 = icmp eq i32 %tmp4, %arg1
42 br i1 %tmp5, label %bb6, label %bb2
44 bb6: ; preds = %bb2, %bb
50 ; This ends up creating a shl with a i64 result type, but an i32 shift amount.
51 ; Because custom type legalization for i32 is enabled, this resulted in
52 ; LowerOperation being called for the amount. This was not expected and
53 ; triggered an assert.
54 define i32 @crash(i32 %x, i32 %y, i32 %z) {
57 ; RV64I-NEXT: sext.w a0, a0
58 ; RV64I-NEXT: seqz a3, a0
59 ; RV64I-NEXT: addw a0, a1, a2
60 ; RV64I-NEXT: slli a1, a3, 3
61 ; RV64I-NEXT: .LBB1_1: # %bb
62 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
63 ; RV64I-NEXT: beq a0, a1, .LBB1_1
64 ; RV64I-NEXT: # %bb.2: # %bar
69 %a = icmp eq i32 %x, 0
71 %c = select i1 %a, i32 8, i32 0
72 %d = icmp eq i32 %b, %c
73 br i1 %d, label %bb, label %bar
79 ; We prefer to sign extend i32 constants for phis. The default behavior in
80 ; SelectionDAGBuilder is zero extend. We have a target hook to override it.
81 define i64 @sext_phi_constants(i32 signext %c) {
82 ; RV64I-LABEL: sext_phi_constants:
84 ; RV64I-NEXT: li a1, -1
85 ; RV64I-NEXT: bnez a0, .LBB2_2
86 ; RV64I-NEXT: # %bb.1: # %iffalse
87 ; RV64I-NEXT: li a1, -2
88 ; RV64I-NEXT: .LBB2_2: # %merge
89 ; RV64I-NEXT: slli a0, a1, 32
90 ; RV64I-NEXT: srli a0, a0, 32
92 %a = icmp ne i32 %c, 0
93 br i1 %a, label %iftrue, label %iffalse
102 %b = phi i32 [-1, %iftrue], [-2, %iffalse]
103 %d = zext i32 %b to i64