Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,13 @@ static bool evaluatePtrAddRecAtMaxBTCWillNotWrap(
return true;
});
if (DerefRK) {
DerefBytesSCEV =
SE.getUMaxExpr(DerefBytesSCEV, SE.getSCEV(DerefRK.IRArgValue));
const SCEV *DerefRKSCEV = SE.getSCEV(DerefRK.IRArgValue);
// Ensure both operands have the same type
Comment thread
kshitijvp marked this conversation as resolved.
Outdated
Type *CommonTy =
SE.getWiderType(DerefBytesSCEV->getType(), DerefRKSCEV->getType());
Comment thread
kshitijvp marked this conversation as resolved.
DerefBytesSCEV = SE.getNoopOrAnyExtend(DerefBytesSCEV, CommonTy);
DerefRKSCEV = SE.getNoopOrAnyExtend(DerefRKSCEV, CommonTy);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why any extend? Both quantities should be positive, so better always use Zext?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

DerefBytesSCEV = SE.getUMaxExpr(DerefBytesSCEV, DerefRKSCEV);
}

if (DerefBytesSCEV->isZero())
Expand Down
31 changes: 31 additions & 0 deletions llvm/test/Transforms/LoopVectorize/early_exit_store_legality.ll
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ exit:
ret void
}

; Function Attrs: mustprogress norecurse nosync nounwind ssp memory(read, inaccessiblemem: write, target_mem0: none, target_mem1: none) uwtable(sync)
Comment thread
kshitijvp marked this conversation as resolved.
Outdated
define void @loop_contains_store_assumed_bounds(ptr noalias %array, ptr readonly %pred, i32 %n) {
; CHECK-LABEL: LV: Checking a loop in 'loop_contains_store_assumed_bounds'
; CHECK: LV: Not vectorizing: Loop may fault.
Expand Down Expand Up @@ -194,6 +195,36 @@ exit:
ret void
}

define void @test_assumed_bounds_type_mismatch(ptr noalias %array, ptr readonly %pred, i32 %n) nosync nofree {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we need a loop with a store? If not, would be good to remove the store and add to llvm/test/Transforms/LoopVectorize/dereferenceable-info-from-assumption-variable-size.ll. It should get vectorized with the crash fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the store is redundant in this case, needs to be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the store instruction is causing faulting load, instead of being vectorized.

; CHECK-LABEL: LV: Checking a loop in 'test_assumed_bounds_type_mismatch'
; CHECK: LV: Not vectorizing: Loop may fault.
entry:
%n_bytes = mul nuw nsw i32 %n, 2
call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %pred, i32 %n_bytes) ]
%tc = sext i32 %n to i64
br label %for.body

for.body:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.inc ]
%st.addr = getelementptr inbounds i16, ptr %array, i64 %iv
%data = load i16, ptr %st.addr, align 2
%inc = add nsw i16 %data, 1
store i16 %inc, ptr %st.addr, align 2
%ee.addr = getelementptr inbounds i16, ptr %pred, i64 %iv
%ee.val = load i16, ptr %ee.addr, align 2
%ee.cond = icmp sgt i16 %ee.val, 500
br i1 %ee.cond, label %exit, label %for.inc

for.inc:
%iv.next = add nuw nsw i64 %iv, 1
%counted.cond = icmp eq i64 %iv.next, %tc
br i1 %counted.cond, label %exit, label %for.body

exit:
ret void
}


define void @loop_contains_store_to_pointer_with_no_deref_info(ptr align 2 dereferenceable(40) readonly %load.array, ptr align 2 noalias %array, ptr align 2 dereferenceable(40) readonly %pred) {
; CHECK-LABEL: LV: Checking a loop in 'loop_contains_store_to_pointer_with_no_deref_info'
; CHECK: LV: Not vectorizing: Writes to memory unsupported in early exit loops.
Expand Down