We have analogous rules in instsimplify, etc.., but were missing the same in SCEV. The fold is near trivial, but came up in the context of a larger change.
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
return S;
+ // 0 udiv Y == 0
+ if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS))
+ if (LHSC->getValue()->isZero())
+ return LHS;
+
if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
if (RHSC->getValue()->isOne())
return LHS; // X udiv 1 --> x
; CHECK-LABEL: @test11
%t0 = udiv i64 0, %a
; CHECK: %t0
-; CHECK-NEXT: --> (0 /u %a)
+; CHECK-NEXT: --> 0
ret i64 %t0
}