|
| 1 | +;=========================== begin_copyright_notice ============================ |
| 2 | +; |
| 3 | +; Copyright (C) 2025 Intel Corporation |
| 4 | +; |
| 5 | +; SPDX-License-Identifier: MIT |
| 6 | +; |
| 7 | +;============================ end_copyright_notice ============================= |
| 8 | +; |
| 9 | +; ------------------------------------------------ |
| 10 | +; REQUIRES: llvm-14-plus |
| 11 | +; RUN: igc_opt --opaque-pointers --igc-gep-lowering -S < %s 2>&1 | FileCheck %s |
| 12 | +; ------------------------------------------------ |
| 13 | +; GEPLowering - verify that address arithmetic based on first GEP index is not |
| 14 | +; applied, when GEP index can be negative and zext if used on |
| 15 | +; negative index may turn it into large positive value |
| 16 | +; ------------------------------------------------ |
| 17 | + |
| 18 | +define spir_func void @test_gep_overflow(ptr addrspace(1) %src, i32 %conv13) { |
| 19 | +; CHECK-LABEL: @test_gep_overflow( |
| 20 | +; CHECK-NEXT: entry: |
| 21 | +; CHECK-NEXT: [[SUB:%.*]] = add nsw i32 [[CONV13:%.*]], -2 |
| 22 | +; CHECK-NEXT: [[IDX_EXT19:%.*]] = zext i32 [[SUB]] to i64 |
| 23 | +; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr addrspace(1) [[SRC:%.*]] to i64 |
| 24 | +; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[IDX_EXT19]], 2 |
| 25 | +; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP0]], [[TMP1]] |
| 26 | +; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr addrspace(1) |
| 27 | +; CHECK-NEXT: [[SUB22:%.*]] = add nsw i32 [[CONV13]], -1 |
| 28 | +; CHECK-NEXT: [[IDX_EXT35:%.*]] = zext i32 [[SUB22]] to i64 |
| 29 | +; CHECK-NEXT: [[TMP4:%.*]] = ptrtoint ptr addrspace(1) [[SRC]] to i64 |
| 30 | +; CHECK-NEXT: [[TMP5:%.*]] = shl i64 [[IDX_EXT35]], 2 |
| 31 | +; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP4]], [[TMP5]] |
| 32 | +; CHECK-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr addrspace(1) |
| 33 | +; CHECK-NEXT: ret void |
| 34 | +; |
| 35 | +entry: |
| 36 | + %sub = add nsw i32 %conv13, -2 |
| 37 | + %idx.ext19 = zext i32 %sub to i64 |
| 38 | + %add.ptr20 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx.ext19 |
| 39 | + %sub22 = add nsw i32 %conv13, -1 |
| 40 | + %idx.ext35 = zext i32 %sub22 to i64 |
| 41 | + %add.ptr36 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx.ext35 |
| 42 | + ret void |
| 43 | +} |
| 44 | + |
| 45 | +define spir_func void @test_gep_no_overflow(ptr addrspace(1) %src, i32 %conv13) { |
| 46 | +; CHECK-LABEL: @test_gep_no_overflow( |
| 47 | +; CHECK-NEXT: entry: |
| 48 | +; CHECK-NEXT: [[SUB:%.*]] = add nuw nsw i32 [[CONV13:%.*]], -2 |
| 49 | +; CHECK-NEXT: [[IDX_EXT19:%.*]] = zext i32 [[SUB]] to i64 |
| 50 | +; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr addrspace(1) [[SRC:%.*]] to i64 |
| 51 | +; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[IDX_EXT19]], 2 |
| 52 | +; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP0]], [[TMP1]] |
| 53 | +; CHECK-NEXT: [[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr addrspace(1) |
| 54 | +; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP2]], 4 |
| 55 | +; CHECK-NEXT: [[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr addrspace(1) |
| 56 | +; CHECK-NEXT: ret void |
| 57 | +; |
| 58 | +entry: |
| 59 | + %sub = add nsw nuw i32 %conv13, -2 |
| 60 | + %idx.ext19 = zext i32 %sub to i64 |
| 61 | + %add.ptr20 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx.ext19 |
| 62 | + %sub22 = add nsw nuw i32 %conv13, -1 |
| 63 | + %idx.ext35 = zext i32 %sub22 to i64 |
| 64 | + %add.ptr36 = getelementptr inbounds float, ptr addrspace(1) %src, i64 %idx.ext35 |
| 65 | + ret void |
| 66 | +} |
| 67 | + |
| 68 | +!igc.functions = !{!0, !4} |
| 69 | + |
| 70 | +!0 = !{ptr @test_gep_overflow, !1} |
| 71 | +!1 = !{!2, !3} |
| 72 | +!2 = !{!"function_type", i32 0} |
| 73 | +!3 = !{!"implicit_arg_desc"} |
| 74 | +!4 = !{ptr @test_gep_no_overflow, !1} |
0 commit comments