[llvm] 23a1c0a - [instcombine] Test for zero initialisation optimisation of integer product
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 24 07:54:43 PDT 2022
Author: Zain Jaffal
Date: 2022-08-24T15:54:20+01:00
New Revision: 23a1c0a7790a4a8df9c9b01eae00a6fea08e1a42
URL: https://github.com/llvm/llvm-project/commit/23a1c0a7790a4a8df9c9b01eae00a6fea08e1a42
DIFF: https://github.com/llvm/llvm-project/commit/23a1c0a7790a4a8df9c9b01eae00a6fea08e1a42.diff
LOG: [instcombine] Test for zero initialisation optimisation of integer product
Following the work on `D131672` we do the same optimisations for integer products.
We add tests to check if a loop gets removed if we repeatdly multiply an array elements with an accumulator initalised to zero
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D132553
Added:
llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll
Modified:
Removed:
llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll b/llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll
similarity index 65%
rename from llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll
rename to llvm/test/Transforms/InstCombine/remove-loop-phi-multiply-by-zero.ll
index 57489317b50b..962cbade85da 100644
--- 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 @@ end: ; preds = %for.body
%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
+}
More information about the llvm-commits
mailing list