[llvm] 14d8f15 - [SCEV] Fold (0 udiv %x) to 0
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 30 08:32:57 PDT 2021
Author: Philip Reames
Date: 2021-06-30T08:31:13-07:00
New Revision: 14d8f1546a0483ef54a7a09442848d0a470c94c0
URL: https://github.com/llvm/llvm-project/commit/14d8f1546a0483ef54a7a09442848d0a470c94c0
DIFF: https://github.com/llvm/llvm-project/commit/14d8f1546a0483ef54a7a09442848d0a470c94c0.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/fold.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 990f3d6040f4..97ea60f93c54 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -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
diff --git a/llvm/test/Analysis/ScalarEvolution/fold.ll b/llvm/test/Analysis/ScalarEvolution/fold.ll
index 72b62ecaeffc..c23029d521d4 100644
--- a/llvm/test/Analysis/ScalarEvolution/fold.ll
+++ b/llvm/test/Analysis/ScalarEvolution/fold.ll
@@ -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
}
More information about the llvm-commits
mailing list