[PATCH] D47965: [SCEV] Canonicalize "A /u C1 /u C2" to "A /u (C1*C2)".
Tim Shen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 11 11:49:30 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334425: [SCEV] Canonicalize "A /u C1 /u C2" to "A /u (C1*C2)". (authored by timshen, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D47965?vs=150800&id=150801#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47965
Files:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
Index: llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
===================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
+++ llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
@@ -98,3 +98,31 @@
; CHECK-NEXT: --> 0
ret void
}
+
+define i64 @test8(i64 %a) {
+; CHECK-LABEL: @test8
+ %t0 = udiv i64 %a, 56
+ %t1 = udiv i64 %t0, 56
+; CHECK: %t1
+; CHECK-NEXT: --> (%a /u 3136)
+ ret i64 %t1
+}
+
+define i64 @test9(i64 %a) {
+; CHECK-LABEL: @test9
+ %t0 = udiv i64 %a, 100000000000000
+ %t1 = udiv i64 %t0, 100000000000000
+; CHECK: %t1
+; CHECK-NEXT: --> 0
+ ret i64 %t1
+}
+
+define i64 @test10(i64 %a, i64 %b) {
+; CHECK-LABEL: @test9
+ %t0 = udiv i64 %a, 100000000000000
+ %t1 = udiv i64 %t0, 100000000000000
+ %t2 = mul i64 %b, %t1
+; CHECK: %t2
+; CHECK-NEXT: --> 0
+ ret i64 %t2
+}
Index: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp
@@ -3066,6 +3066,21 @@
}
}
}
+
+ // (A/B)/C --> A/(B*C) if safe and B*C can be folded.
+ if (const SCEVUDivExpr *OtherDiv = dyn_cast<SCEVUDivExpr>(LHS)) {
+ if (auto *DivisorConstant =
+ dyn_cast<SCEVConstant>(OtherDiv->getRHS())) {
+ bool Overflow = false;
+ APInt NewRHS =
+ DivisorConstant->getAPInt().umul_ov(RHSC->getAPInt(), Overflow);
+ if (Overflow) {
+ return getConstant(RHSC->getType(), 0, false);
+ }
+ return getUDivExpr(OtherDiv->getLHS(), getConstant(NewRHS));
+ }
+ }
+
// (A+B)/C --> (A/C + B/C) if safe and A/C and B/C can be folded.
if (const SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(LHS)) {
SmallVector<const SCEV *, 4> Operands;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47965.150801.patch
Type: text/x-patch
Size: 1890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180611/8bafb060/attachment.bin>
More information about the llvm-commits
mailing list