1; RUN: llc -verify-machineinstrs -ppc-reduce-cr-logicals \ 2; RUN: -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s 3 4; Test case is reduced from the snappy benchmark. 5; Verify MachineLICM will always hoist trivially rematerializable instructions even when register pressure is high. 6 7%"class.snappy::SnappyDecompressor" = type <{ %"class.snappy::Source"*, i8*, i8*, i32, i8, [5 x i8], [6 x i8] }> 8%"class.snappy::Source" = type { i32 (...)** } 9%"struct.snappy::iovec" = type { i8*, i64 } 10%"class.snappy::SnappyIOVecWriter" = type { %"struct.snappy::iovec"*, i64, i64, i64, i64, i64 } 11 12@_ZN6snappy8internalL10char_tableE = internal unnamed_addr constant [5 x i16] [i16 1, i16 2052, i16 4097, i16 8193, i16 2], align 2 13@_ZN6snappy8internalL8wordmaskE = internal unnamed_addr constant [5 x i32] [i32 0, i32 255, i32 65535, i32 16777215, i32 -1], align 4 14 15; Function Attrs: argmemonly nounwind 16declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1) #2 17; Function Attrs: argmemonly nounwind 18declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #2 19 20define linkonce_odr void @ZN6snappyDecompressor_(%"class.snappy::SnappyDecompressor"* %this, %"class.snappy::SnappyIOVecWriter"* %writer) { 21; CHECK-LABEL: ZN6snappyDecompressor_: 22; CHECK: # %bb.0: # %entry 23; CHECK: addis 3, 2, _ZN6snappy8internalL8wordmaskE@toc@ha 24; CHECK-DAG: addi 25, 3, _ZN6snappy8internalL8wordmaskE@toc@l 25; CHECK-DAG: addis 5, 2, _ZN6snappy8internalL10char_tableE@toc@ha 26; CHECK-DAG: addi 24, 5, _ZN6snappy8internalL10char_tableE@toc@l 27; CHECK: .LBB0_2: # %for.cond 28; CHECK-NOT: addis {{[0-9]+}}, 2, _ZN6snappy8internalL8wordmaskE@toc@ha 29; CHECK-NOT: addis {{[0-9]+}}, 2, _ZN6snappy8internalL10char_tableE@toc@ha 30; CHECK: bctrl 31entry: 32 %ip_limit_ = getelementptr inbounds %"class.snappy::SnappyDecompressor", %"class.snappy::SnappyDecompressor"* %this, i64 0, i32 2 33 %0 = bitcast i8** %ip_limit_ to i64* 34 %curr_iov_index_.i = getelementptr inbounds %"class.snappy::SnappyIOVecWriter", %"class.snappy::SnappyIOVecWriter"* %writer, i64 0, i32 2 35 %curr_iov_written_.i = getelementptr inbounds %"class.snappy::SnappyIOVecWriter", %"class.snappy::SnappyIOVecWriter"* %writer, i64 0, i32 3 36 %1 = bitcast i64* %curr_iov_written_.i to <2 x i64>* 37 br label %for.cond 38 39for.cond: ; preds = %if.end82, %if.then56, %if.end49, %entry 40 %ip.0 = phi i8* [ null, %entry ], [ %add.ptr50, %if.end49 ], [ null, %if.then56 ], [ undef, %if.end82 ] 41 %incdec.ptr = getelementptr inbounds i8, i8* %ip.0, i64 1 42 %2 = load i8, i8* %ip.0, align 1 43 %conv = zext i8 %2 to i32 44 br i1 undef, label %if.then7, label %if.else 45 46if.then7: ; preds = %for.cond 47 %3 = lshr i32 %conv, 2 48 %add = add nuw nsw i32 %3, 1 49 %conv9 = zext i32 %add to i64 50 %4 = load i64, i64* %0, align 8 51 %sub.ptr.sub13 = sub i64 %4, 0 52 %5 = load i64, i64* undef, align 8 53 %6 = load i64, i64* null, align 8 54 %sub.i = sub i64 %5, %6 55 %cmp.i = icmp ult i32 %add, 17 56 %cmp2.i = icmp ugt i64 %sub.ptr.sub13, 20 57 %or.cond.i = and i1 %cmp.i, %cmp2.i 58 %cmp4.i = icmp ugt i64 %sub.i, 15 59 %or.cond13.i = and i1 %or.cond.i, %cmp4.i 60 br i1 %or.cond13.i, label %land.lhs.true5.i, label %if.end17 61 62land.lhs.true5.i: ; preds = %if.then7 63 %7 = load %"struct.snappy::iovec"*, %"struct.snappy::iovec"** undef, align 8 64 %8 = load i64, i64* %curr_iov_index_.i, align 8 65 %9 = load i64, i64* %curr_iov_written_.i, align 8 66 %sub6.i = sub i64 0, %9 67 %cmp7.i = icmp ugt i64 %sub6.i, 15 68 br i1 %cmp7.i, label %cleanup102, label %if.end17 69 70if.end17: ; preds = %land.lhs.true5.i, %if.then7 71 %sub = add nsw i64 %conv9, -60 72 %10 = load i32, i32* undef, align 4 73 %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* @_ZN6snappy8internalL8wordmaskE, i64 0, i64 %sub 74 %11 = load i32, i32* %arrayidx, align 4 75 %and21 = and i32 %11, %10 76 %add22 = add i32 %and21, 1 77 %conv23 = zext i32 %add22 to i64 78 %add.ptr24 = getelementptr inbounds i8, i8* %incdec.ptr, i64 %sub 79 br label %if.end25 80 81if.end25: ; preds = %if.end17 82 %sub.ptr.rhs.cast28 = ptrtoint i8* %add.ptr24 to i64 83 %cmp30233 = icmp ugt i64 %conv23, 0 84 br i1 %cmp30233, label %while.body.preheader, label %while.end 85 86while.body.preheader: ; preds = %if.end25 87 %add.i158256 = add i64 %6, 0 88 %cmp.i160257 = icmp ugt i64 %add.i158256, %5 89 br i1 %cmp.i160257, label %cleanup105, label %while.cond.preheader.i 90 91while.cond.preheader.i: ; preds = %while.body.preheader 92 %call39 = call i8* undef(%"class.snappy::Source"* undef, i64* nonnull undef) 93 unreachable 94 95while.end: ; preds = %if.end25 96 br label %while.cond.preheader.i176 97 98while.cond.preheader.i176: ; preds = %while.end 99 br i1 undef, label %if.end49, label %while.body.lr.ph.i182 100 101while.body.lr.ph.i182: ; preds = %while.cond.preheader.i176 102 %.pre.i181 = load i64, i64* %curr_iov_written_.i, align 8 103 %12 = load %"struct.snappy::iovec"*, %"struct.snappy::iovec"** undef, align 8 104 %13 = load i64, i64* %curr_iov_index_.i, align 8 105 %iov_len.i185 = getelementptr inbounds %"struct.snappy::iovec", %"struct.snappy::iovec"* %12, i64 %13, i32 1 106 %14 = load i64, i64* %iov_len.i185, align 8 107 br label %cond.end.i190 108 109cond.end.i190: ; preds = %while.body.lr.ph.i182 110 br i1 undef, label %if.end18.i207, label %if.then10.i193 111 112if.then10.i193: ; preds = %cond.end.i190 113 %add12.i191 = add i64 %13, 1 114 %iov_len22.phi.trans.insert.i194 = getelementptr inbounds %"struct.snappy::iovec", %"struct.snappy::iovec"* %12, i64 %add12.i191, i32 1 115 %.pre48.i195 = load i64, i64* %iov_len22.phi.trans.insert.i194, align 8 116 br label %if.end18.i207 117 118if.end18.i207: ; preds = %if.then10.i193, %cond.end.i190 119 %15 = phi i64 [ %.pre.i181, %cond.end.i190 ], [ 0, %if.then10.i193 ] 120 %16 = phi i64 [ %14, %cond.end.i190 ], [ %.pre48.i195, %if.then10.i193 ] 121 %17 = phi i64 [ %13, %cond.end.i190 ], [ %add12.i191, %if.then10.i193 ] 122 %sub.i197 = sub i64 %16, %15 123 %cmp.i.i198 = icmp ult i64 %sub.i197, %conv23 124 %.sroa.speculated.i199 = select i1 %cmp.i.i198, i64 %sub.i197, i64 %conv23 125 %iov_base.i.i200 = getelementptr inbounds %"struct.snappy::iovec", %"struct.snappy::iovec"* %12, i64 %17, i32 0 126 %18 = load i8*, i8** %iov_base.i.i200, align 8 127 %add.ptr.i.i201 = getelementptr inbounds i8, i8* %18, i64 %15 128 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %add.ptr.i.i201, i8* %add.ptr24, i64 %.sroa.speculated.i199, i1 false) #12 129 %add30.i203 = add i64 0, %.sroa.speculated.i199 130 store i64 %add30.i203, i64* null, align 8 131 %.pre245 = load i64, i64* %0, align 8 132 br label %if.end49 133 134if.end49: ; preds = %if.end18.i207, %while.cond.preheader.i176 135 %19 = phi i64 [ %.pre245, %if.end18.i207 ], [ %4, %while.cond.preheader.i176 ] 136 %add.ptr50 = getelementptr inbounds i8, i8* %add.ptr24, i64 %conv23 137 %sub.ptr.sub54 = sub i64 %19, 0 138 %cmp55 = icmp slt i64 %sub.ptr.sub54, 5 139 br i1 %cmp55, label %if.then56, label %for.cond 140 141if.then56: ; preds = %if.end49 142 br label %for.cond 143 144if.else: ; preds = %for.cond 145 %idxprom = zext i8 %2 to i64 146 %arrayidx68 = getelementptr inbounds [5 x i16], [5 x i16]* @_ZN6snappy8internalL10char_tableE, i64 0, i64 %idxprom 147 %20 = load i16, i16* %arrayidx68, align 2 148 %conv69 = zext i16 %20 to i64 149 %21 = load i32, i32* undef, align 4 150 %shr71 = lshr i64 %conv69, 11 151 %arrayidx72 = getelementptr inbounds [5 x i32], [5 x i32]* @_ZN6snappy8internalL8wordmaskE, i64 0, i64 %shr71 152 %22 = load i32, i32* %arrayidx72, align 4 153 %and73 = and i32 %22, %21 154 %conv74 = zext i32 %and73 to i64 155 %add79 = add nuw nsw i64 0, %conv74 156 %call80 = call zeroext i1 @_ZN6snappy17SnappyIOVecWriterAppendFromSelfEmm(%"class.snappy::SnappyIOVecWriter"* %writer, i64 %add79, i64 undef) 157 br i1 %call80, label %if.end82, label %cleanup105 158 159if.end82: ; preds = %if.else 160 br label %for.cond 161 162cleanup102: ; preds = %land.lhs.true5.i 163 %iov_base.i.i = getelementptr inbounds %"struct.snappy::iovec", %"struct.snappy::iovec"* %7, i64 %8, i32 0 164 %23 = load i8*, i8** %iov_base.i.i, align 8 165 %add.ptr.i.i = getelementptr inbounds i8, i8* %23, i64 %9 166 call void @llvm.memmove.p0i8.p0i8.i64(i8* %add.ptr.i.i, i8* %incdec.ptr, i64 16, i1 false) #12 167 %24 = load <2 x i64>, <2 x i64>* %1, align 8 168 %25 = insertelement <2 x i64> undef, i64 %conv9, i32 0 169 %26 = shufflevector <2 x i64> %25, <2 x i64> undef, <2 x i32> zeroinitializer 170 %27 = add <2 x i64> %24, %26 171 store <2 x i64> %27, <2 x i64>* undef, align 8 172 unreachable 173 174cleanup105: ; preds = %if.else, %while.body.preheader 175 ret void 176} 177 178; Function Attrs: inlinehint 179declare zeroext i1 @_ZN6snappy17SnappyIOVecWriterAppendFromSelfEmm(%"class.snappy::SnappyIOVecWriter"*, i64, i64) local_unnamed_addr #10 align 2 180