[llvm] 44bb409 - [ConstraintElimination] Do not crash on vector GEP in decomposeGEP
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 2 02:04:56 PDT 2022
Author: Bjorn Pettersson
Date: 2022-11-02T10:04:11+01:00
New Revision: 44bb4099cd75dfd4800effe98b08ed720d71029a
URL: https://github.com/llvm/llvm-project/commit/44bb4099cd75dfd4800effe98b08ed720d71029a
DIFF: https://github.com/llvm/llvm-project/commit/44bb4099cd75dfd4800effe98b08ed720d71029a.diff
LOG: [ConstraintElimination] Do not crash on vector GEP in decomposeGEP
Commit 359bc5c541ae4b02 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
Added:
llvm/test/Transforms/ConstraintElimination/geps-ptrvector.ll
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 94b890e5660da..8b9076aff8fa9 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -209,9 +209,7 @@ decomposeGEP(GetElementPtrInst &GEP,
const DataLayout &DL) {
// Do not reason about pointers where the index size is larger than 64 bits,
// as the coefficients used to encode constraints are 64 bit integers.
- unsigned AS =
- cast<PointerType>(GEP.getPointerOperand()->getType())->getAddressSpace();
- if (DL.getIndexSizeInBits(AS) > 64)
+ if (DL.getIndexTypeSizeInBits(GEP.getPointerOperand()->getType()) > 64)
return {};
if (!GEP.isInBounds())
diff --git a/llvm/test/Transforms/ConstraintElimination/geps-ptrvector.ll b/llvm/test/Transforms/ConstraintElimination/geps-ptrvector.ll
new file mode 100644
index 0000000000000..e30830fff7c76
--- /dev/null
+++ b/llvm/test/Transforms/ConstraintElimination/geps-ptrvector.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
+
+; Should not crash when GEP pointer operand is a vector.
+define <2 x i1> @test.vectorgep(<2 x ptr> %vec) {
+; CHECK-LABEL: @test.vectorgep(
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, <2 x ptr> [[VEC:%.*]], i64 0
+; CHECK-NEXT: [[COND:%.*]] = icmp ule <2 x ptr> [[GEP]], zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[COND]]
+;
+ %gep = getelementptr inbounds i32, <2 x ptr> %vec, i64 0
+ %cond = icmp ule <2 x ptr> %gep, zeroinitializer
+ ret <2 x i1> %cond
+}
More information about the llvm-commits
mailing list