Skip to content

Commit 96dc8d7

Browse files
committed
[Hexagon] Masked and unmasked load to same base -> load and two selects
1 parent 4878851 commit 96dc8d7

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,6 @@ auto AlignVectors::createAddressGroups() -> bool {
521521
return !llvm::any_of(
522522
G.second, [&](auto &I) { return HVC.HST.isTypeForHVX(I.ValTy); });
523523
});
524-
// Remove groups where everything is properly aligned.
525-
erase_if(AddrGroups, [&](auto &G) {
526-
return llvm::all_of(G.second,
527-
[&](auto &I) { return I.HaveAlign >= I.NeedAlign; });
528-
});
529524

530525
return !AddrGroups.empty();
531526
}
@@ -1382,6 +1377,11 @@ auto HexagonVectorCombine::isSafeToMoveBeforeInBB(const Instruction &In,
13821377
const Instruction &I = *It;
13831378
if (llvm::is_contained(Ignore, &I))
13841379
continue;
1380+
// assume intrinsic can be ignored
1381+
if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
1382+
if (II->getIntrinsicID() == Intrinsic::assume)
1383+
continue;
1384+
}
13851385
// Parts based on isSafeToMoveBefore from CoveMoverUtils.cpp.
13861386
if (I.mayThrow())
13871387
return false;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; RUN: opt -march=hexagon -hexagon-vc < %s | FileCheck %s
2+
3+
; Test that the HexagonVectorCombine pass identifies instruction
4+
; pairs whose difference in pointers is zero. This creates a vector
5+
; load to handle masked and unmasked loads that have no base
6+
; pointer difference and replaces the masked and unmasked loads
7+
; with selects
8+
9+
; CHECK: select
10+
11+
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
12+
target triple = "hexagon"
13+
14+
define dllexport void @f0(i8** %a0) local_unnamed_addr #0 {
15+
b0:
16+
%v0 = load i8*, i8** %a0, align 4
17+
%v1 = getelementptr i8, i8* %v0, i32 1794
18+
%v2 = bitcast i8* %v1 to <64 x i16>*
19+
call void @llvm.assume(i1 true) [ "align"(i8* %v0, i32 128) ]
20+
%v3 = load <64 x i16>, <64 x i16>* %v2, align 128
21+
%v4 = add <64 x i16> %v3, %v3
22+
call void @llvm.assume(i1 true) [ "align"(i8* %v0, i32 128) ]
23+
%v5 = tail call <64 x i16> @llvm.masked.load.v64i16.p0v64i16(<64 x i16>* %v2, i32 128, <64 x i1> <i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true>, <64 x i16> undef)
24+
call void @llvm.assume(i1 true) [ "align"(i8* %v0, i32 128) ]
25+
%v6 = add <64 x i16> %v4, %v5
26+
store <64 x i16> %v6, <64 x i16>* %v2, align 128
27+
ret void
28+
}
29+
30+
; Function Attrs: nofree nosync nounwind willreturn
31+
declare void @llvm.assume(i1 noundef) #1
32+
33+
; Function Attrs: argmemonly nofree nosync nounwind readonly willreturn
34+
declare <64 x i16> @llvm.masked.load.v64i16.p0v64i16(<64 x i16>*, i32 immarg, <64 x i1>, <64 x i16>) #2
35+
36+
attributes #0 = { "target-features"="+hvxv68,+hvx-length128b,+hvxv68,+hvx-length128b" }
37+
attributes #1 = { nofree nosync nounwind willreturn }
38+
attributes #2 = { argmemonly nofree nosync nounwind readonly willreturn }

0 commit comments

Comments
 (0)