Skip to content

Commit 24ed4f3

Browse files
mkariganigcbot
authored andcommitted
Changes in code.
1 parent 6fbfdfd commit 24ed4f3

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

IGC/Compiler/CISACodeGen/MemOpt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,13 @@ bool SymbolicPointer::checkTerms(const Term *T, const Term *OtherT, int64_t &Off
22332233
if (checkInstructions(Inst, OtherInst))
22342234
return true;
22352235

2236+
// OpNum == 3 is a sentinel set by checkInstructions() when both operands of
2237+
// the top-level instructions are identical. Guard here before calling
2238+
// getOperand(OpNum) to avoid an out-of-bounds access on a two-operand
2239+
// BinaryOperator.
2240+
if (OpNum == 3)
2241+
return false;
2242+
22362243
auto InstOp0 = dyn_cast<BinaryOperator>(Inst->getOperand(OpNum));
22372244
auto OtherInstOp0 = dyn_cast<BinaryOperator>(OtherInst->getOperand(OpNum));
22382245
if (checkInstructions(InstOp0, OtherInstOp0))
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2026 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; Regression test for a crash in SymbolicPointer::checkTerms().
10+
;
11+
; When both operands of the top-level binary instruction are identical across
12+
; the two pointer chains, checkInstructions() sets the sentinel OpNum = 3.
13+
; Without the early-exit guard added immediately after the first
14+
; checkInstructions() call, the code would proceed to call getOperand(3) on a
15+
; two-operand BinaryOperator, triggering an LLVM assertion / abort.
16+
;
17+
; Pattern exercised (both top-level sub nsw have the same two operands):
18+
;
19+
; %add0 = add nsw i32 %base, %delta
20+
; %idx0 = sub nsw i32 %add0, %k <- chain 0, top-level operands: (%add0, %k)
21+
;
22+
; %add1 = add nsw i32 %base, %delta
23+
; %idx1r = sub nsw i32 %add1, %k <- chain 1, top-level operands: (%add1, %k)
24+
; %idx1 = add nsw i32 %idx1r, 1 <- one element further
25+
;
26+
; RUN: igc_opt --opaque-pointers %s -S -o - --basic-aa -igc-memopt -instcombine | FileCheck %s
27+
28+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64"
29+
target triple = "spir64-unknown-unknown"
30+
31+
; CHECK-LABEL: @check_terms_same_operands
32+
; Verify that the pass completes without crashing and the function is present.
33+
; CHECK: ret void
34+
define spir_kernel void @check_terms_same_operands(
35+
ptr addrspace(1) %dst,
36+
ptr addrspace(1) %src,
37+
i32 %base,
38+
i32 %delta,
39+
i32 %k) {
40+
entry:
41+
; Chain 0: index = (base + delta) - k
42+
%add0 = add nsw i32 %base, %delta
43+
%idx0 = sub nsw i32 %add0, %k
44+
%idx0e = sext i32 %idx0 to i64
45+
%ptr0 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx0e
46+
%v0 = load float, ptr addrspace(1) %ptr0, align 4
47+
48+
; Chain 1: index = (base + delta) - k + 1
49+
; The top-level sub nsw has the same two operands as chain 0's sub nsw,
50+
; which is the exact condition that triggers the OpNum = 3 sentinel.
51+
%add1 = add nsw i32 %base, %delta
52+
%idx1r = sub nsw i32 %add1, %k
53+
%idx1 = add nsw i32 %idx1r, 1
54+
%idx1e = sext i32 %idx1 to i64
55+
%ptr1 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx1e
56+
%v1 = load float, ptr addrspace(1) %ptr1, align 4
57+
58+
; Use both values to prevent DCE.
59+
%sum = fadd float %v0, %v1
60+
store float %sum, ptr addrspace(1) %dst, align 4
61+
ret void
62+
}

0 commit comments

Comments
 (0)