1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[SCEV] Fold (0 udiv %x) to 0

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.
This commit is contained in:
Philip Reames 2021-06-30 08:31:13 -07:00
parent 7110dfba97
commit 0b160e9666
2 changed files with 6 additions and 1 deletions

View File

@ -3268,6 +3268,11 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
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

View File

@ -132,6 +132,6 @@ define i64 @test11(i64 %a) {
; CHECK-LABEL: @test11
%t0 = udiv i64 0, %a
; CHECK: %t0
; CHECK-NEXT: --> (0 /u %a)
; CHECK-NEXT: --> 0
ret i64 %t0
}