Skip to content

Commit 482c2b8

Browse files
committed
[LV] Fix the bug!
1 parent a1c3462 commit 482c2b8

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,9 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
882882

883883
// If any of M's operands demand more bits than MinBW then M cannot be
884884
// performed safely in MinBW.
885-
if (any_of(MI->operands(), [&DB, MinBW](Use &U) {
885+
auto *Call = dyn_cast<CallInst>(MI);
886+
auto Ops = Call ? Call->args() : MI->operands();
887+
if (any_of(Ops, [&DB, MinBW](Use &U) {
886888
auto *CI = dyn_cast<ConstantInt>(U);
887889
// For constants shift amounts, check if the shift would result in
888890
// poison.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,8 @@ void VPlanTransforms::truncateToMinimalBitwidths(
16151615
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
16161616
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
16171617
if (!isa<VPWidenRecipe, VPWidenCastRecipe, VPReplicateRecipe,
1618-
VPWidenSelectRecipe, VPWidenLoadRecipe>(&R))
1618+
VPWidenSelectRecipe, VPWidenLoadRecipe, VPWidenIntrinsicRecipe>(
1619+
&R))
16191620
continue;
16201621

16211622
VPValue *ResultVPV = R.getVPSingleValue();

llvm/test/Transforms/LoopVectorize/pr87407.ll

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

44
define void @pr87407(ptr %dst, i64 %n) {
5+
; CHECK-LABEL: define void @pr87407(
6+
; CHECK-SAME: ptr [[DST:%.*]], i64 [[N:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*]]:
8+
; CHECK-NEXT: [[ZEXT_0:%.*]] = zext i8 0 to i64
9+
; CHECK-NEXT: br label %[[LOOP:.*]]
10+
; CHECK: [[LOOP]]:
11+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ 0, %[[ENTRY]] ]
12+
; CHECK-NEXT: [[MAX:%.*]] = tail call i64 @llvm.umax.i64(i64 [[ZEXT_0]], i64 0)
13+
; CHECK-NEXT: [[CMP_MAX_0:%.*]] = icmp ne i64 [[MAX]], 0
14+
; CHECK-NEXT: [[ZEXT_CMP:%.*]] = zext i1 [[CMP_MAX_0]] to i64
15+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[ZEXT_CMP]] to i32
16+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[TRUNC]], 8
17+
; CHECK-NEXT: [[RES:%.*]] = trunc i32 [[SHL]] to i8
18+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
19+
; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp ne i64 [[IV_NEXT]], [[N]]
20+
; CHECK-NEXT: br i1 [[EXIT_COND]], label %[[LOOP]], label %[[EXIT:.*]]
21+
; CHECK: [[EXIT]]:
22+
; CHECK-NEXT: [[RES_LCSSA:%.*]] = phi i8 [ [[RES]], %[[LOOP]] ]
23+
; CHECK-NEXT: store i8 [[RES_LCSSA]], ptr [[DST]], align 1
24+
; CHECK-NEXT: ret void
25+
;
526
entry:
627
%zext.0 = zext i8 0 to i64
728
br label %loop

0 commit comments

Comments
 (0)