Update accumulateConstantOffset and collectOffset to implicitly truncate struct field offsets. This fixes crashes in the new tests, where the field offset does not fit in the index width. PR: https://github.com/llvm/llvm-project/pull/213436
28 lines
1 KiB
LLVM
28 lines
1 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
|
|
; RUN: opt -passes=instcombine -S %s | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-p:16:16"
|
|
|
|
%s = type { [65536 x i8], i8 }
|
|
|
|
; Offset of the struct's second field does not fit into a 16 bit pointer.
|
|
define ptr @gep_of_gep_struct_offset_exceeds_index_width(ptr %p, i16 %i) {
|
|
; CHECK-LABEL: define ptr @gep_of_gep_struct_offset_exceeds_index_width(
|
|
; CHECK-SAME: ptr [[P:%.*]], i16 [[I:%.*]]) {
|
|
; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds i8, ptr [[P]], i16 [[I]]
|
|
; CHECK-NEXT: ret ptr [[B]]
|
|
;
|
|
%a = getelementptr inbounds %s, ptr %p, i16 0, i32 1
|
|
%b = getelementptr inbounds i8, ptr %a, i16 %i
|
|
ret ptr %b
|
|
}
|
|
|
|
define ptr @gep_struct_offset_exceeds_index_width_multiple(ptr %p) {
|
|
; CHECK-LABEL: define ptr @gep_struct_offset_exceeds_index_width_multiple(
|
|
; CHECK-SAME: ptr [[P:%.*]]) {
|
|
; CHECK-NEXT: ret ptr [[P]]
|
|
;
|
|
%a = getelementptr inbounds %s, ptr %p, i16 0, i32 1
|
|
%b = getelementptr inbounds %s, ptr %a, i16 0, i32 1
|
|
ret ptr %b
|
|
}
|