Skip to content

Commit e5d9ab0

Browse files
author
Krzysztof Parzyszek
committed
[Hexagon] Fix insertion point for pointer difference calculation
HVC::calculatePointerDifference inserts temporary instructions for simplification, and calulation of known bits. These instructions were inserted at the end of a basic block (after the terminator), which caused BB->getTerminator() to return nullptr. This, in turn, caused a crash when a PHI instruction was examined in computeKnownBits.
1 parent 5e12c18 commit e5d9ab0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ auto HexagonVectorCombine::calculatePointerDifference(Value *Ptr0,
19301930
Value *Ptr1) const
19311931
-> std::optional<int> {
19321932
struct Builder : IRBuilder<> {
1933-
Builder(BasicBlock *B) : IRBuilder<>(B) {}
1933+
Builder(BasicBlock *B) : IRBuilder<>(B->getTerminator()) {}
19341934
~Builder() {
19351935
for (Instruction *I : llvm::reverse(ToErase))
19361936
I->eraseFromParent();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llc -march=hexagon < %s | FileCheck %s
2+
3+
; Check that this doesn't crash.
4+
; CHECK: jumpr r31
5+
6+
target triple = "hexagon"
7+
8+
define void @f0() #0 {
9+
b0:
10+
br label %b1
11+
12+
b1: ; preds = %b0, %b1
13+
%v0 = phi i32 [ %v9, %b1 ], [ 0, %b0 ]
14+
%v1 = zext i32 %v0 to i64
15+
%v2 = getelementptr inbounds float, ptr null, i64 %v1
16+
store float poison, ptr %v2, align 16
17+
%v3 = or i32 %v0, 3
18+
%v4 = zext i32 %v3 to i64
19+
%v5 = getelementptr inbounds float, ptr null, i64 %v4
20+
store float poison, ptr %v5, align 4
21+
%v6 = add nuw nsw i32 %v0, 4
22+
%v7 = icmp ult i32 %v3, 63
23+
%v8 = select i1 %v7, i1 true, i1 false
24+
%v9 = select i1 %v7, i32 %v6, i32 0
25+
br i1 %v8, label %b1, label %b2, !prof !0
26+
27+
b2:
28+
ret void
29+
}
30+
31+
attributes #0 = { "target-features"="+hvxv69,+hvx-length128b,+hvx-qfloat,-hvx-ieee-fp" }
32+
33+
!0 = !{!"branch_weights", i32 -2147481600, i32 2048}

0 commit comments

Comments
 (0)