diff --git a/llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll b/llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll rename from llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll rename to llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll --- a/llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll +++ b/llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll @@ -273,3 +273,149 @@ %f_prod.0.lcssa = phi double [ %mul, %for.body ] ret double %f_prod.0.lcssa } + +define i32 @test_int_phi_operands(i32* %arr_d) { +; CHECK-LABEL: @test_int_phi_operands( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[FOR_BODY:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[I_02:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[F_PROD_01:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[MUL:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[ARR_D:%.*]], i64 [[I_02]] +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 +; CHECK-NEXT: [[MUL]] = mul nsw i32 [[F_PROD_01]], [[TMP0]] +; CHECK-NEXT: [[INC]] = add i64 [[I_02]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INC]], 1000 +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[END:%.*]] +; CHECK: end: +; CHECK-NEXT: ret i32 [[MUL]] +; +entry: + br label %for.body + +for.body: ; preds = %entry, %for.body + %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] + %f_prod.01 = phi i32 [ 0, %entry ], [ %mul, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %arr_d, i64 %i.02 + %0 = load i32, i32* %arrayidx, align 4 + %mul = mul nsw i32 %f_prod.01, %0 + %inc = add i64 %i.02, 1 + %cmp = icmp ult i64 %inc, 1000 + br i1 %cmp, label %for.body, label %end + +end: ; preds = %for.body + %f_prod.0.lcssa = phi i32 [ %mul, %for.body ] + ret i32 %f_prod.0.lcssa +} + +define i32 @test_int_phi_operands_initalise_to_non_zero(i32* %arr_d) { +; CHECK-LABEL: @test_int_phi_operands_initalise_to_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[FOR_BODY:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[I_02:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[F_PROD_01:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[MUL:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[ARR_D:%.*]], i64 [[I_02]] +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 +; CHECK-NEXT: [[MUL]] = mul i32 [[F_PROD_01]], [[TMP0]] +; CHECK-NEXT: [[INC]] = add i64 [[I_02]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INC]], 1000 +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[END:%.*]] +; CHECK: end: +; CHECK-NEXT: ret i32 [[MUL]] +; +entry: + br label %for.body + +for.body: ; preds = %entry, %for.body + %i.02 = phi i64 [ 0, %entry ], [ %inc, %for.body ] + %f_prod.01 = phi i32 [ 1, %entry ], [ %mul, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %arr_d, i64 %i.02 + %0 = load i32, i32* %arrayidx, align 4 + %mul = mul i32 %f_prod.01, %0 + %inc = add i64 %i.02, 1 + %cmp = icmp ult i64 %inc, 1000 + br i1 %cmp, label %for.body, label %end + +end: ; preds = %for.body + %f_prod.0.lcssa = phi i32 [ %mul, %for.body ] + ret i32 %f_prod.0.lcssa +} + +define i32 @test_multiple_int_phi_operands(i32* %arr_d, i1 %entry_cond) { +; CHECK-LABEL: @test_multiple_int_phi_operands( +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 [[ENTRY_COND:%.*]], label [[FOR_BODY:%.*]], label [[ENTRY_2:%.*]] +; CHECK: entry_2: +; CHECK-NEXT: br label [[FOR_BODY]] +; CHECK: for.body: +; CHECK-NEXT: [[I_02:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ 0, [[ENTRY_2]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[F_PROD_01:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ 0, [[ENTRY_2]] ], [ [[MUL:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[ARR_D:%.*]], i64 [[I_02]] +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 +; CHECK-NEXT: [[MUL]] = mul i32 [[F_PROD_01]], [[TMP0]] +; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[I_02]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[I_02]], 999 +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[END:%.*]] +; CHECK: end: +; CHECK-NEXT: ret i32 [[MUL]] +; +entry: + br i1 %entry_cond, label %for.body, label %entry_2 + +entry_2: + br label %for.body + +for.body: ; preds = %entry, %for.body + %i.02 = phi i64 [ 0, %entry ], [0, %entry_2], [ %inc, %for.body ] + %f_prod.01 = phi i32 [ 0, %entry ], [0, %entry_2], [ %mul, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %arr_d, i64 %i.02 + %0 = load i32, i32* %arrayidx, align 4 + %mul = mul i32 %f_prod.01, %0 + %inc = add i64 %i.02, 1 + %cmp = icmp ult i64 %inc, 1000 + br i1 %cmp, label %for.body, label %end + +end: ; preds = %for.body + %f_prod.0.lcssa = phi i32 [ %mul, %for.body ] + ret i32 %f_prod.0.lcssa +} + +define i32 @test_multiple_int_phi_operands_initalise_to_non_zero(i32* %arr_d, i1 %entry_cond) { +; CHECK-LABEL: @test_multiple_int_phi_operands_initalise_to_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 [[ENTRY_COND:%.*]], label [[FOR_BODY:%.*]], label [[ENTRY_2:%.*]] +; CHECK: entry_2: +; CHECK-NEXT: br label [[FOR_BODY]] +; CHECK: for.body: +; CHECK-NEXT: [[I_02:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ 0, [[ENTRY_2]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[F_PROD_01:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ 1, [[ENTRY_2]] ], [ [[MUL:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[ARR_D:%.*]], i64 [[I_02]] +; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 +; CHECK-NEXT: [[MUL]] = mul i32 [[F_PROD_01]], [[TMP0]] +; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[I_02]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[I_02]], 999 +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[END:%.*]] +; CHECK: end: +; CHECK-NEXT: ret i32 [[MUL]] +; +entry: + br i1 %entry_cond, label %for.body, label %entry_2 + +entry_2: + br label %for.body + +for.body: ; preds = %entry, %for.body + %i.02 = phi i64 [ 0, %entry ], [0, %entry_2], [ %inc, %for.body ] + %f_prod.01 = phi i32 [ 0, %entry ], [1, %entry_2], [ %mul, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %arr_d, i64 %i.02 + %0 = load i32, i32* %arrayidx, align 4 + %mul = mul i32 %f_prod.01, %0 + %inc = add i64 %i.02, 1 + %cmp = icmp ult i64 %inc, 1000 + br i1 %cmp, label %for.body, label %end + +end: ; preds = %for.body + %f_prod.0.lcssa = phi i32 [ %mul, %for.body ] + ret i32 %f_prod.0.lcssa +}