[llvm] 18423c7 - [SCCP] Do not attempt to create constexpr for a scalable vector GEP
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 11 04:07:57 PDT 2023
Author: Rahul Anand Radhakrishnan
Date: 2023-08-11T11:06:07Z
New Revision: 18423c7e1f9d973df697f7f3c1ad2a60be582aef
URL: https://github.com/llvm/llvm-project/commit/18423c7e1f9d973df697f7f3c1ad2a60be582aef
DIFF: https://github.com/llvm/llvm-project/commit/18423c7e1f9d973df697f7f3c1ad2a60be582aef.diff
LOG: [SCCP] Do not attempt to create constexpr for a scalable vector GEP
Scalable vector GEPs are not constants and trying to create one for
these GEPs causes an assertion failure.
Reviewed By: nikic, paulwalker-arm
Differential Revision: https://reviews.llvm.org/D157590
Added:
llvm/test/Transforms/SCCP/vscale-gep.ll
Modified:
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
llvm/test/Transforms/SCCP/2009-09-24-byval-ptr.ll
llvm/test/Transforms/SCCP/apint-bigint2.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index de3626a24212c2..4821d344512b80 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1539,11 +1539,8 @@ void SCCPInstVisitor::visitGetElementPtrInst(GetElementPtrInst &I) {
return (void)markOverdefined(&I);
}
- Constant *Ptr = Operands[0];
- auto Indices = ArrayRef(Operands.begin() + 1, Operands.end());
- Constant *C =
- ConstantExpr::getGetElementPtr(I.getSourceElementType(), Ptr, Indices);
- markConstant(&I, C);
+ if (Constant *C = ConstantFoldInstOperands(&I, Operands, DL))
+ markConstant(&I, C);
}
void SCCPInstVisitor::visitStoreInst(StoreInst &SI) {
diff --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
index 003f80fa260ff2..57db1cf71a9b9e 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression.ll
@@ -30,13 +30,13 @@ define internal i64 @zoo(i1 %flag) {
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[FLAG:%.*]], label [[PLUS:%.*]], label [[MINUS:%.*]]
; CHECK: plus:
-; CHECK-NEXT: [[TMP0:%.*]] = call i64 @func2.2(ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i32 0, i32 3))
+; CHECK-NEXT: [[TMP0:%.*]] = call i64 @func2.2(ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i64 0, i32 3))
; CHECK-NEXT: br label [[MERGE:%.*]]
; CHECK: minus:
-; CHECK-NEXT: [[TMP1:%.*]] = call i64 @func2.1(ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i32 0, i32 4))
+; CHECK-NEXT: [[TMP1:%.*]] = call i64 @func2.1(ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4))
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
-; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ ptrtoint (ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i32 0, i32 3) to i64), [[PLUS]] ], [ ptrtoint (ptr getelementptr inbounds ([[STRUCT:%.*]], ptr @Global, i32 0, i32 4) to i64), [[MINUS]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 3) to i64), [[PLUS]] ], [ ptrtoint (ptr getelementptr inbounds ([[STRUCT]], ptr @Global, i64 0, i32 4) to i64), [[MINUS]] ]
; CHECK-NEXT: ret i64 [[TMP2]]
;
entry:
diff --git a/llvm/test/Transforms/SCCP/2009-09-24-byval-ptr.ll b/llvm/test/Transforms/SCCP/2009-09-24-byval-ptr.ll
index c2a3c12ec7daf1..34ef4349c786c0 100644
--- a/llvm/test/Transforms/SCCP/2009-09-24-byval-ptr.ll
+++ b/llvm/test/Transforms/SCCP/2009-09-24-byval-ptr.ll
@@ -31,7 +31,7 @@ return: ; preds = %entry
define internal i32 @vfu2(ptr byval(%struct.MYstr) align 4 %u) nounwind readonly {
; CHECK-LABEL: @vfu2(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr getelementptr inbounds ([[STRUCT_MYSTR:%.*]], ptr @mystr, i32 0, i32 1), align 4
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr getelementptr inbounds ([[STRUCT_MYSTR:%.*]], ptr @mystr, i64 0, i32 1), align 4
; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr @mystr, align 1
; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], [[TMP0]]
diff --git a/llvm/test/Transforms/SCCP/apint-bigint2.ll b/llvm/test/Transforms/SCCP/apint-bigint2.ll
index 79c0cfcf7da803..6092c092bea5cb 100644
--- a/llvm/test/Transforms/SCCP/apint-bigint2.ll
+++ b/llvm/test/Transforms/SCCP/apint-bigint2.ll
@@ -23,7 +23,7 @@ define i101 @large_aggregate() {
; CHECK-LABEL: @large_aggregate(
; CHECK-NEXT: [[D:%.*]] = and i101 undef, 1
; CHECK-NEXT: [[DD:%.*]] = or i101 [[D]], 1
-; CHECK-NEXT: [[G:%.*]] = getelementptr i101, ptr getelementptr inbounds ([6 x i101], ptr @Y, i32 0, i32 5), i101 [[DD]]
+; CHECK-NEXT: [[G:%.*]] = getelementptr i101, ptr getelementptr inbounds ([6 x i101], ptr @Y, i64 0, i64 5), i101 [[DD]]
; CHECK-NEXT: [[L3:%.*]] = load i101, ptr [[G]], align 4
; CHECK-NEXT: ret i101 [[L3]]
;
@@ -40,7 +40,7 @@ define i101 @large_aggregate_2() {
; CHECK-LABEL: @large_aggregate_2(
; CHECK-NEXT: [[D:%.*]] = and i101 undef, 1
; CHECK-NEXT: [[DD:%.*]] = or i101 [[D]], 1
-; CHECK-NEXT: [[G:%.*]] = getelementptr i101, ptr getelementptr inbounds ([6 x i101], ptr @Y, i32 0, i32 5), i101 [[DD]]
+; CHECK-NEXT: [[G:%.*]] = getelementptr i101, ptr getelementptr inbounds ([6 x i101], ptr @Y, i64 0, i64 5), i101 [[DD]]
; CHECK-NEXT: [[L3:%.*]] = load i101, ptr [[G]], align 4
; CHECK-NEXT: ret i101 [[L3]]
;
@@ -54,7 +54,7 @@ define i101 @large_aggregate_2() {
define void @index_too_large() {
; CHECK-LABEL: @index_too_large(
-; CHECK-NEXT: store ptr getelementptr ([6 x i101], ptr @Y, i101 1537416322793603071, i101 4), ptr undef, align 8
+; CHECK-NEXT: store ptr getelementptr ([6 x i101], ptr @Y, i64 187649984473770, i64 2), ptr undef, align 8
; CHECK-NEXT: ret void
;
%ptr1 = getelementptr [6 x i101], ptr @Y, i32 0, i32 -1
diff --git a/llvm/test/Transforms/SCCP/vscale-gep.ll b/llvm/test/Transforms/SCCP/vscale-gep.ll
new file mode 100644
index 00000000000000..30756cfc9063a8
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/vscale-gep.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=sccp -S | FileCheck %s
+
+define ptr @scalable_vector_getelementptr(i64 %x) {
+; CHECK-LABEL: @scalable_vector_getelementptr(
+; CHECK-NEXT: [[PTR:%.*]] = getelementptr <vscale x 4 x i32>, ptr null, i64 1
+; CHECK-NEXT: ret ptr [[PTR]]
+;
+ %ptr = getelementptr <vscale x 4 x i32>, ptr null, i64 1
+ ret ptr %ptr
+}
More information about the llvm-commits
mailing list