Skip to content

Commit 639ec9c

Browse files
committed
[LV] Strip unmaintainable MinBWs assert
tryToWiden attempts to replace an Instruction with a Constant from SCEV, but forgets to erase the Instruction from the MinBWs map, leading to an assert in VPlanTransforms::truncateToMinimalBitwidths. Going forward, the assertion in truncateToMinimalBitwidths is unmaintainable, as LV could simplify the expression at any point: fix the bug by stripping the unmaintable assertion. Fixes #125278.
1 parent b4e2d02 commit 639ec9c

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,6 @@ static void licm(VPlan &Plan) {
15981598

15991599
void VPlanTransforms::truncateToMinimalBitwidths(
16001600
VPlan &Plan, const MapVector<Instruction *, uint64_t> &MinBWs) {
1601-
#ifndef NDEBUG
1602-
// Count the processed recipes and cross check the count later with MinBWs
1603-
// size, to make sure all entries in MinBWs have been handled.
1604-
unsigned NumProcessedRecipes = 0;
1605-
#endif
16061601
// Keep track of created truncates, so they can be re-used. Note that we
16071602
// cannot use RAUW after creating a new truncate, as this would could make
16081603
// other uses have different types for their operands, making them invalidly
@@ -1624,9 +1619,6 @@ void VPlanTransforms::truncateToMinimalBitwidths(
16241619
if (!NewResSizeInBits)
16251620
continue;
16261621

1627-
#ifndef NDEBUG
1628-
NumProcessedRecipes++;
1629-
#endif
16301622
// If the value wasn't vectorized, we must maintain the original scalar
16311623
// type. Skip those here, after incrementing NumProcessedRecipes. Also
16321624
// skip casts which do not need to be handled explicitly here, as
@@ -1650,7 +1642,6 @@ void VPlanTransforms::truncateToMinimalBitwidths(
16501642
// Add an entry to ProcessedTruncs to avoid counting the same
16511643
// operand multiple times.
16521644
ProcessedTruncs[Op] = nullptr;
1653-
NumProcessedRecipes += 1;
16541645
}
16551646
}
16561647
#endif
@@ -1714,19 +1705,11 @@ void VPlanTransforms::truncateToMinimalBitwidths(
17141705
NewOp->insertBefore(&R);
17151706
} else {
17161707
PH->appendRecipe(NewOp);
1717-
#ifndef NDEBUG
1718-
auto *OpInst = dyn_cast<Instruction>(Op->getLiveInIRValue());
1719-
bool IsContained = MinBWs.contains(OpInst);
1720-
NumProcessedRecipes += IsContained;
1721-
#endif
17221708
}
17231709
}
17241710

17251711
}
17261712
}
1727-
1728-
assert(MinBWs.size() == NumProcessedRecipes &&
1729-
"some entries in MinBWs haven't been processed");
17301713
}
17311714

17321715
/// Remove BranchOnCond recipes with true conditions together with removing

llvm/test/Transforms/LoopVectorize/pr125278.ll

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
; REQUIRES: asserts
2-
; RUN: not --crash opt -passes=loop-vectorize -force-vector-width=4 -disable-output %s
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
2+
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
33

44
define void @pr125278(ptr %dst, i64 %n) {
5+
; CHECK-LABEL: define void @pr125278(
6+
; CHECK-SAME: ptr [[DST:%.*]], i64 [[N:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: [[TRUE_EXT:%.*]] = zext i1 true to i32
9+
; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N]], i64 1)
10+
; CHECK-NEXT: br label %[[COND:.*]]
11+
; CHECK: [[COND_LOOPEXIT:.*]]:
12+
; CHECK-NEXT: br label %[[COND]]
13+
; CHECK: [[COND]]:
14+
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[UMAX]], 4
15+
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
16+
; CHECK: [[VECTOR_PH]]:
17+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[UMAX]], 4
18+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[UMAX]], [[N_MOD_VF]]
19+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
20+
; CHECK: [[VECTOR_BODY]]:
21+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
22+
; CHECK-NEXT: store i8 1, ptr [[DST]], align 1
23+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
24+
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
25+
; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
26+
; CHECK: [[MIDDLE_BLOCK]]:
27+
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[UMAX]], [[N_VEC]]
28+
; CHECK-NEXT: br i1 [[CMP_N]], label %[[COND_LOOPEXIT]], label %[[SCALAR_PH]]
29+
; CHECK: [[SCALAR_PH]]:
30+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[COND]] ]
31+
; CHECK-NEXT: br label %[[LOOP:.*]]
32+
; CHECK: [[LOOP]]:
33+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
34+
; CHECK-NEXT: [[FALSE_EXT:%.*]] = zext i1 false to i32
35+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[FALSE_EXT]], [[TRUE_EXT]]
36+
; CHECK-NEXT: [[XOR_TRUNC:%.*]] = trunc i32 [[XOR]] to i8
37+
; CHECK-NEXT: store i8 [[XOR_TRUNC]], ptr [[DST]], align 1
38+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
39+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[IV_NEXT]], [[N]]
40+
; CHECK-NEXT: br i1 [[CMP]], label %[[LOOP]], label %[[COND_LOOPEXIT]], !llvm.loop [[LOOP3:![0-9]+]]
41+
;
542
entry:
643
%true.ext = zext i1 true to i32
744
br label %cond

0 commit comments

Comments
 (0)