Skip to content

Commit 9dca765

Browse files
committed
Lambda early return, remove unused test IR and improve comment formatting
1 parent 0804843 commit 9dca765

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3651,26 +3651,26 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
36513651
auto ExtendAndReplaceConstantOp = [&Ctx](VPWidenCastRecipe *ExtA,
36523652
VPWidenCastRecipe *&ExtB,
36533653
VPValue *&ValB, VPWidenRecipe *Mul) {
3654-
if (ExtA && !ExtB && ValB->isLiveIn()) {
3655-
Type *NarrowTy = Ctx.Types.inferScalarType(ExtA->getOperand(0));
3656-
Instruction::CastOps ExtOpc = ExtA->getOpcode();
3657-
const APInt *Const;
3658-
if (!match(ValB, m_APInt(Const)) ||
3659-
!llvm::canConstantBeExtended(
3660-
Const, NarrowTy, TTI::getPartialReductionExtendKind(ExtOpc)))
3661-
return;
3662-
// The truncate ensures that the type of each extended operand is the
3663-
// same, and it's been proven that the constant can be extended from
3664-
// NarrowTy safely. Necessary since ExtA's extended operand would be
3665-
// e.g. an i8, while the const will likely be an i32. This will be
3666-
// elided by later optimisations.
3667-
VPBuilder Builder(Mul);
3668-
auto *Trunc =
3669-
Builder.createWidenCast(Instruction::CastOps::Trunc, ValB, NarrowTy);
3670-
Type *WideTy = Ctx.Types.inferScalarType(ExtA);
3671-
ValB = ExtB = Builder.createWidenCast(ExtOpc, Trunc, WideTy);
3672-
Mul->setOperand(1, ExtB);
3673-
}
3654+
if (!ExtA || ExtB || !ValB->isLiveIn())
3655+
return;
3656+
Type *NarrowTy = Ctx.Types.inferScalarType(ExtA->getOperand(0));
3657+
Instruction::CastOps ExtOpc = ExtA->getOpcode();
3658+
const APInt *Const;
3659+
if (!match(ValB, m_APInt(Const)) ||
3660+
!llvm::canConstantBeExtended(
3661+
Const, NarrowTy, TTI::getPartialReductionExtendKind(ExtOpc)))
3662+
return;
3663+
// The truncate ensures that the type of each extended operand is the
3664+
// same, and it's been proven that the constant can be extended from
3665+
// NarrowTy safely. Necessary since ExtA's extended operand would be
3666+
// e.g. an i8, while the const will likely be an i32. This will be
3667+
// elided by later optimisations.
3668+
VPBuilder Builder(Mul);
3669+
auto *Trunc =
3670+
Builder.createWidenCast(Instruction::CastOps::Trunc, ValB, NarrowTy);
3671+
Type *WideTy = Ctx.Types.inferScalarType(ExtA);
3672+
ValB = ExtB = Builder.createWidenCast(ExtOpc, Trunc, WideTy);
3673+
Mul->setOperand(1, ExtB);
36743674
};
36753675

36763676
// Try to match reduce.add(mul(...)).
@@ -3709,8 +3709,8 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
37093709
auto *Ext0 = dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe());
37103710
auto *Ext1 = dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe());
37113711

3712-
// Convert reduce.add(ext(mul(ext, const))) to reduce.add(ext(mul(ext,
3713-
// ext(const))))
3712+
// reduce.add(ext(mul(ext, const)))
3713+
// -> reduce.add(ext(mul(ext, ext(const))))
37143714
ExtendAndReplaceConstantOp(Ext0, Ext1, B, Mul);
37153715

37163716
// Match reduce.add(ext(mul(ext(A), ext(B))))

llvm/test/Transforms/LoopVectorize/reduction-inloop.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,9 +2800,9 @@ exit:
28002800
ret i64 %r.0.lcssa
28012801
}
28022802

2803-
define i32 @reduction_expression_ext_mulacc_livein(ptr %a, ptr %b, i16 %c) {
2803+
define i32 @reduction_expression_ext_mulacc_livein(ptr %a, i16 %c) {
28042804
; CHECK-LABEL: define i32 @reduction_expression_ext_mulacc_livein(
2805-
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i16 [[C:%.*]]) {
2805+
; CHECK-SAME: ptr [[A:%.*]], i16 [[C:%.*]]) {
28062806
; CHECK-NEXT: [[ENTRY:.*:]]
28072807
; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
28082808
; CHECK: [[VECTOR_PH]]:
@@ -2828,7 +2828,7 @@ define i32 @reduction_expression_ext_mulacc_livein(ptr %a, ptr %b, i16 %c) {
28282828
; CHECK-NEXT: ret i32 [[TMP5]]
28292829
;
28302830
; CHECK-INTERLEAVED-LABEL: define i32 @reduction_expression_ext_mulacc_livein(
2831-
; CHECK-INTERLEAVED-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i16 [[C:%.*]]) {
2831+
; CHECK-INTERLEAVED-SAME: ptr [[A:%.*]], i16 [[C:%.*]]) {
28322832
; CHECK-INTERLEAVED-NEXT: [[ENTRY:.*:]]
28332833
; CHECK-INTERLEAVED-NEXT: br label %[[VECTOR_PH:.*]]
28342834
; CHECK-INTERLEAVED: [[VECTOR_PH]]:
@@ -2871,9 +2871,6 @@ for.body: ; preds = %for.body, %entry
28712871
%gep.a = getelementptr i8, ptr %a, i64 %iv
28722872
%load.a = load i8, ptr %gep.a, align 1
28732873
%ext.a = zext i8 %load.a to i16
2874-
%gep.b = getelementptr i8, ptr %b, i64 %iv
2875-
%load.b = load i8, ptr %gep.b, align 1
2876-
%ext.b = zext i8 %load.b to i16
28772874
%mul = mul i16 %c, %ext.a
28782875
%mul.ext = zext i16 %mul to i32
28792876
%add = add i32 %mul.ext, %accum

0 commit comments

Comments
 (0)