[llvm] e8dc17a - [LoopInterchange] Skip non SCEV-able operands in cost function.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 8 03:44:19 PST 2020
Author: Florian Hahn
Date: 2020-11-08T11:41:19Z
New Revision: e8dc17a2b7710a2f055220a9d5cca68817787736
URL: https://github.com/llvm/llvm-project/commit/e8dc17a2b7710a2f055220a9d5cca68817787736
DIFF: https://github.com/llvm/llvm-project/commit/e8dc17a2b7710a2f055220a9d5cca68817787736.diff
LOG: [LoopInterchange] Skip non SCEV-able operands in cost function.
This fixes a crash when trying to get a SCEV expression for operands
that are not SCEV-able.
Added:
llvm/test/Transforms/LoopInterchange/vector-gep-operand.ll
Modified:
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index c902f8ae24ca..afa4c4dfaa66 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1039,6 +1039,10 @@ int LoopInterchangeProfitability::getInstrOrderCost() {
bool FoundInnerInduction = false;
bool FoundOuterInduction = false;
for (unsigned i = 0; i < NumOp; ++i) {
+ // Skip operands that are not SCEV-able.
+ if (!SE->isSCEVable(GEP->getOperand(i)->getType()))
+ continue;
+
const SCEV *OperandVal = SE->getSCEV(GEP->getOperand(i));
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(OperandVal);
if (!AR)
diff --git a/llvm/test/Transforms/LoopInterchange/vector-gep-operand.ll b/llvm/test/Transforms/LoopInterchange/vector-gep-operand.ll
new file mode 100644
index 000000000000..3bc69c3d2b0f
--- /dev/null
+++ b/llvm/test/Transforms/LoopInterchange/vector-gep-operand.ll
@@ -0,0 +1,67 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -loop-interchange -loop-interchange-threshold=-10 -S %s | FileCheck %s
+
+; The test contains a GEP with an operand that is not SCEV-able. Make sure
+; loop-interchange does not crash.
+define void @test([256 x float]* noalias %src, float* %dst) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[INNER_PREHEADER:%.*]]
+; CHECK: outer.header.preheader:
+; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
+; CHECK: outer.header:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[OUTER_LATCH:%.*]] ], [ 0, [[OUTER_HEADER_PREHEADER:%.*]] ]
+; CHECK-NEXT: br label [[INNER_SPLIT1:%.*]]
+; CHECK: inner.preheader:
+; CHECK-NEXT: br label [[INNER:%.*]]
+; CHECK: inner:
+; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[TMP0:%.*]], [[INNER_SPLIT:%.*]] ], [ 0, [[INNER_PREHEADER]] ]
+; CHECK-NEXT: br label [[OUTER_HEADER_PREHEADER]]
+; CHECK: inner.split1:
+; CHECK-NEXT: [[SRC_GEP:%.*]] = getelementptr inbounds [256 x float], [256 x float]* [[SRC:%.*]], <2 x i64> <i64 0, i64 1>, i64 [[J]]
+; CHECK-NEXT: [[SRC_0:%.*]] = extractelement <2 x float*> [[SRC_GEP]], i32 0
+; CHECK-NEXT: [[LV_0:%.*]] = load float, float* [[SRC_0]], align 4
+; CHECK-NEXT: [[ADD_0:%.*]] = fadd float [[LV_0]], 1.000000e+00
+; CHECK-NEXT: [[DST_GEP:%.*]] = getelementptr inbounds float, float* [[DST:%.*]], i64 [[J]]
+; CHECK-NEXT: store float [[ADD_0]], float* [[DST_GEP]], align 4
+; CHECK-NEXT: [[J_NEXT:%.*]] = add nuw nsw i64 [[J]], 1
+; CHECK-NEXT: [[INNER_EXITCOND:%.*]] = icmp eq i64 [[J_NEXT]], 100
+; CHECK-NEXT: br label [[OUTER_LATCH]]
+; CHECK: inner.split:
+; CHECK-NEXT: [[TMP0]] = add nuw nsw i64 [[J]], 1
+; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[TMP0]], 100
+; CHECK-NEXT: br i1 [[TMP1]], label [[EXIT:%.*]], label [[INNER]]
+; CHECK: outer.latch:
+; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: [[OUTER_EXITCOND:%.*]] = icmp eq i32 [[I_NEXT]], 100
+; CHECK-NEXT: br i1 [[OUTER_EXITCOND]], label [[INNER_SPLIT]], label [[OUTER_HEADER]]
+; CHECK: exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %outer.header
+
+outer.header:
+ %i = phi i32 [ %i.next, %outer.latch ], [ 0, %entry ]
+ br label %inner
+
+inner:
+ %j = phi i64 [ 0, %outer.header ], [ %j.next, %inner ]
+ %src.gep = getelementptr inbounds [256 x float], [256 x float]* %src, <2 x i64> <i64 0, i64 1>, i64 %j
+ %src.0 = extractelement <2 x float*> %src.gep, i32 0
+ %lv.0 = load float, float* %src.0
+ %add.0 = fadd float %lv.0, 1.0
+ %dst.gep = getelementptr inbounds float, float* %dst, i64 %j
+ store float %add.0, float* %dst.gep
+ %j.next = add nuw nsw i64 %j, 1
+ %inner.exitcond = icmp eq i64 %j.next, 100
+ br i1 %inner.exitcond, label %outer.latch, label %inner
+
+outer.latch:
+ %i.next = add nuw nsw i32 %i, 1
+ %outer.exitcond = icmp eq i32 %i.next, 100
+ br i1 %outer.exitcond, label %exit, label %outer.header
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list