Skip to content

Commit 44bb409

Browse files
committed
[ConstraintElimination] Do not crash on vector GEP in decomposeGEP
Commit 359bc5c caused Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failures in decomposeGEP when the GEP pointer operand is a vector. Fix is to use DataLayout::getIndexTypeSizeInBits when fetching the index size, as it will use the scalar type in case of a ptr vector. Differential Revision: https://reviews.llvm.org/D137185
1 parent 9a9b904 commit 44bb409

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ decomposeGEP(GetElementPtrInst &GEP,
209209
const DataLayout &DL) {
210210
// Do not reason about pointers where the index size is larger than 64 bits,
211211
// as the coefficients used to encode constraints are 64 bit integers.
212-
unsigned AS =
213-
cast<PointerType>(GEP.getPointerOperand()->getType())->getAddressSpace();
214-
if (DL.getIndexSizeInBits(AS) > 64)
212+
if (DL.getIndexTypeSizeInBits(GEP.getPointerOperand()->getType()) > 64)
215213
return {};
216214

217215
if (!GEP.isInBounds())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
; Should not crash when GEP pointer operand is a vector.
5+
define <2 x i1> @test.vectorgep(<2 x ptr> %vec) {
6+
; CHECK-LABEL: @test.vectorgep(
7+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, <2 x ptr> [[VEC:%.*]], i64 0
8+
; CHECK-NEXT: [[COND:%.*]] = icmp ule <2 x ptr> [[GEP]], zeroinitializer
9+
; CHECK-NEXT: ret <2 x i1> [[COND]]
10+
;
11+
%gep = getelementptr inbounds i32, <2 x ptr> %vec, i64 0
12+
%cond = icmp ule <2 x ptr> %gep, zeroinitializer
13+
ret <2 x i1> %cond
14+
}

0 commit comments

Comments
 (0)