diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4737,7 +4737,7 @@ ShiftAmounts.push_back(C); bool Safe = llvm::all_of(ShiftAmounts, [](Constant *C) { - auto *CI = dyn_cast(C); + auto *CI = dyn_cast_or_null(C); return CI && CI->getValue().ult(C->getType()->getIntegerBitWidth()); }); return !Safe; diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -943,6 +943,7 @@ TEST(ValueTracking, canCreatePoisonOrUndef) { std::string AsmHead = + "@s = external dso_local global i32, align 1\n" "declare i32 @g(i32)\n" "define void @f(i32 %x, i32 %y, float %fx, float %fy, i1 %cond, " "<4 x i32> %vx, <4 x i32> %vx2, %svx, i8* %p) {\n"; @@ -1001,7 +1002,11 @@ {{true, false}, "call i32 @g(i32 %x)"}, {{false, false}, "call noundef i32 @g(i32 %x)"}, {{true, false}, "fcmp nnan oeq float %fx, %fy"}, - {{false, false}, "fcmp oeq float %fx, %fy"}}; + {{false, false}, "fcmp oeq float %fx, %fy"}, + {{true, false}, + "ashr <4 x i32> %vx, select (i1 icmp sgt (i32 ptrtoint (i32* @s to " + "i32), i32 1), <4 x i32> zeroinitializer, <4 x i32> )"}}; std::string AssemblyStr = AsmHead; for (auto &Itm : Data)