[PATCH] D118696: Fix incorrect TypeSize->uint64_t cast in InductionDescriptor::isInductionPHI
David Sherwood via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 01:39:31 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1badfbb4fc1a: Fix incorrect TypeSize->uint64_t cast in InductionDescriptor::isInductionPHI (authored by david-arm).
Changed prior to commit:
https://reviews.llvm.org/D118696?vs=406414&id=407421#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118696/new/
https://reviews.llvm.org/D118696
Files:
llvm/lib/Analysis/IVDescriptors.cpp
llvm/unittests/Analysis/IVDescriptorsTest.cpp
Index: llvm/unittests/Analysis/IVDescriptorsTest.cpp
===================================================================
--- llvm/unittests/Analysis/IVDescriptorsTest.cpp
+++ llvm/unittests/Analysis/IVDescriptorsTest.cpp
@@ -97,6 +97,47 @@
});
}
+TEST(IVDescriptorsTest, LoopWithScalableTypes) {
+ // Parse the module.
+ LLVMContext Context;
+
+ std::unique_ptr<Module> M =
+ parseIR(Context,
+ R"(define void @foo(<vscale x 4 x float>* %ptr) {
+entry:
+ br label %for.body
+
+for.body:
+ %lsr.iv1 = phi <vscale x 4 x float>* [ %0, %for.body ], [ %ptr, %entry ]
+ %j.0117 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
+ %lsr.iv12 = bitcast <vscale x 4 x float>* %lsr.iv1 to i8*
+ %inc = add nuw nsw i64 %j.0117, 1
+ %uglygep = getelementptr i8, i8* %lsr.iv12, i64 4
+ %0 = bitcast i8* %uglygep to <vscale x 4 x float>*
+ %cmp = icmp ne i64 %inc, 1024
+ br i1 %cmp, label %for.body, label %end
+
+end:
+ ret void
+})");
+
+ runWithLoopInfoAndSE(
+ *M, "foo", [&](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
+ Function::iterator FI = F.begin();
+ // First basic block is entry - skip it.
+ BasicBlock *Header = &*(++FI);
+ assert(Header->getName() == "for.body");
+ Loop *L = LI.getLoopFor(Header);
+ EXPECT_NE(L, nullptr);
+ PHINode *Inst_iv = dyn_cast<PHINode>(&Header->front());
+ assert(Inst_iv->getName() == "lsr.iv1");
+ InductionDescriptor IndDesc;
+ bool IsInductionPHI =
+ InductionDescriptor::isInductionPHI(Inst_iv, L, &SE, IndDesc);
+ EXPECT_FALSE(IsInductionPHI);
+ });
+}
+
// Depending on how SCEV deals with ptrtoint cast, the step of a phi could be
// a pointer, and InductionDescriptor used to fail with an assertion.
// So just check that it doesn't assert.
Index: llvm/lib/Analysis/IVDescriptors.cpp
===================================================================
--- llvm/lib/Analysis/IVDescriptors.cpp
+++ llvm/lib/Analysis/IVDescriptors.cpp
@@ -1428,10 +1428,14 @@
ConstantInt *CV = ConstStep->getValue();
const DataLayout &DL = Phi->getModule()->getDataLayout();
- int64_t Size = static_cast<int64_t>(DL.getTypeAllocSize(ElementType));
- if (!Size)
+ TypeSize TySize = DL.getTypeAllocSize(ElementType);
+ // TODO: We could potentially support this for scalable vectors if we can
+ // prove at compile time that the constant step is always a multiple of
+ // the scalable type.
+ if (TySize.isZero() || TySize.isScalable())
return false;
+ int64_t Size = static_cast<int64_t>(TySize.getFixedSize());
int64_t CVSize = CV->getSExtValue();
if (CVSize % Size)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118696.407421.patch
Type: text/x-patch
Size: 2677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220210/c4ff11a0/attachment.bin>
More information about the llvm-commits
mailing list