1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=riscv32 -verify-machineinstrs -mattr=+m | FileCheck %s -check-prefixes=RV32
3 ; RUN: llc < %s -mtriple=riscv64 -verify-machineinstrs -mattr=+m | FileCheck %s -check-prefixes=RV64
6 ; - Addition should be cheaper than multiplication
8 ; The following LLVM IR simulates:
12 ; if (i * 2 > 8192) return ;
13 ; for (int j = 0; ; ++j) {
14 ; int offset = j * i + tmp;
16 ; if (offset + i > 8192) break;
24 ; if (j > 8193) return ;
31 @flags2 = internal global [8193 x i8] zeroinitializer, align 32 ; <[8193 x i8]*> [#uses=1]
33 define void @test(i32 signext %i) nounwind {
35 ; RV32: # %bb.0: # %entry
36 ; RV32-NEXT: slli a1, a0, 1
37 ; RV32-NEXT: lui a3, 2
38 ; RV32-NEXT: blt a3, a1, .LBB0_3
39 ; RV32-NEXT: # %bb.1: # %bb.preheader
40 ; RV32-NEXT: lui a2, %hi(flags2)
41 ; RV32-NEXT: addi a2, a2, %lo(flags2)
42 ; RV32-NEXT: addi a3, a3, 1
43 ; RV32-NEXT: .LBB0_2: # %bb
44 ; RV32-NEXT: # =>This Inner Loop Header: Depth=1
45 ; RV32-NEXT: add a4, a2, a1
46 ; RV32-NEXT: add a1, a1, a0
47 ; RV32-NEXT: sb zero, 0(a4)
48 ; RV32-NEXT: blt a1, a3, .LBB0_2
49 ; RV32-NEXT: .LBB0_3: # %return
53 ; RV64: # %bb.0: # %entry
54 ; RV64-NEXT: slliw a1, a0, 1
55 ; RV64-NEXT: lui a4, 2
56 ; RV64-NEXT: blt a4, a1, .LBB0_3
57 ; RV64-NEXT: # %bb.1: # %bb.preheader
59 ; RV64-NEXT: lui a3, %hi(flags2)
60 ; RV64-NEXT: addi a3, a3, %lo(flags2)
61 ; RV64-NEXT: addiw a4, a4, 1
62 ; RV64-NEXT: .LBB0_2: # %bb
63 ; RV64-NEXT: # =>This Inner Loop Header: Depth=1
64 ; RV64-NEXT: mulw a5, a2, a0
65 ; RV64-NEXT: addw a5, a5, a1
66 ; RV64-NEXT: slli a6, a5, 32
67 ; RV64-NEXT: srli a6, a6, 32
68 ; RV64-NEXT: add a6, a3, a6
69 ; RV64-NEXT: sb zero, 0(a6)
70 ; RV64-NEXT: addw a5, a5, a0
71 ; RV64-NEXT: addiw a2, a2, 1
72 ; RV64-NEXT: blt a5, a4, .LBB0_2
73 ; RV64-NEXT: .LBB0_3: # %return
76 %k_addr.012 = shl i32 %i, 1
77 %tmp14 = icmp sgt i32 %k_addr.012, 8192
79 br i1 %tmp14, label %return, label %bb
82 %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %bb ]
83 %tmp.15 = mul i32 %indvar, %i
84 %tmp.16 = add i32 %tmp.15, %tmp.
85 %gep.upgrd.1 = zext i32 %tmp.16 to i64
86 %tmp = getelementptr [8193 x i8], [8193 x i8]* @flags2, i32 0, i64 %gep.upgrd.1
88 %tmp.17 = add i32 %tmp.16, %i
89 %tmp.upgrd.2 = icmp sgt i32 %tmp.17, 8192
90 %indvar.next = add i32 %indvar, 1
91 br i1 %tmp.upgrd.2, label %return, label %bb