[PATCH] D109786: [SCEV] (udiv X, Y) * Y is always NUW
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 15 11:35:10 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9bdb19cca292: [SCEV] (udiv X, Y) * Y is always NUW (authored by reames).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109786/new/
https://reviews.llvm.org/D109786
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/extract-highbits-variablemask.ll
llvm/test/Analysis/ScalarEvolution/max-be-count-not-constant.ll
llvm/test/Analysis/ScalarEvolution/mul.ll
Index: llvm/test/Analysis/ScalarEvolution/mul.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/mul.ll
+++ llvm/test/Analysis/ScalarEvolution/mul.ll
@@ -7,7 +7,7 @@
; CHECK-NEXT: %udiv = udiv i8 %x, %y
; CHECK-NEXT: --> (%x /u %y) U: full-set S: full-set
; CHECK-NEXT: %res = mul i8 %udiv, %y
-; CHECK-NEXT: --> ((%x /u %y) * %y) U: full-set S: full-set
+; CHECK-NEXT: --> ((%x /u %y) * %y)<nuw> U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @test
;
%udiv = udiv i8 %x, %y
@@ -65,7 +65,7 @@
; CHECK-NEXT: %udiv = udiv i8 %x, %y
; CHECK-NEXT: --> (%x /u (trunc i32 %y32 to i8)) U: full-set S: full-set
; CHECK-NEXT: %res = mul i8 %udiv, %y
-; CHECK-NEXT: --> ((trunc i32 %y32 to i8) * (%x /u (trunc i32 %y32 to i8))) U: full-set S: full-set
+; CHECK-NEXT: --> ((trunc i32 %y32 to i8) * (%x /u (trunc i32 %y32 to i8)))<nuw> U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @test5
;
%y = trunc i32 %y32 to i8
Index: llvm/test/Analysis/ScalarEvolution/max-be-count-not-constant.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/max-be-count-not-constant.ll
+++ llvm/test/Analysis/ScalarEvolution/max-be-count-not-constant.ll
@@ -16,9 +16,9 @@
; CHECK-NEXT: %tmp1 = add nsw i32 %tmp, 2
; CHECK-NEXT: --> (2 + %tmp)<nsw> U: [1,3) S: [1,3)
; CHECK-NEXT: %tmp3 = phi i32 [ 0, %bb ], [ %tmp4, %bb2 ]
-; CHECK-NEXT: --> {0,+,(2 + %tmp)<nsw>}<nuw><nsw><%bb2> U: [0,3) S: [0,3) Exits: ((2 + %tmp)<nsw> * (1 /u (2 + %tmp)<nsw>)) LoopDispositions: { %bb2: Computable }
+; CHECK-NEXT: --> {0,+,(2 + %tmp)<nsw>}<nuw><nsw><%bb2> U: [0,3) S: [0,3) Exits: ((2 + %tmp)<nsw> * (1 /u (2 + %tmp)<nsw>))<nuw> LoopDispositions: { %bb2: Computable }
; CHECK-NEXT: %tmp4 = add nuw nsw i32 %tmp1, %tmp3
-; CHECK-NEXT: --> {(2 + %tmp)<nsw>,+,(2 + %tmp)<nsw>}<nuw><nsw><%bb2> U: [1,5) S: [1,5) Exits: (2 + ((2 + %tmp)<nsw> * (1 /u (2 + %tmp)<nsw>)) + %tmp) LoopDispositions: { %bb2: Computable }
+; CHECK-NEXT: --> {(2 + %tmp)<nsw>,+,(2 + %tmp)<nsw>}<nuw><nsw><%bb2> U: [1,5) S: [1,5) Exits: (2 + ((2 + %tmp)<nsw> * (1 /u (2 + %tmp)<nsw>))<nuw> + %tmp) LoopDispositions: { %bb2: Computable }
; CHECK-NEXT: Determining loop execution counts for: @pluto
; CHECK-NEXT: Loop %bb2: backedge-taken count is (1 /u (2 + %tmp)<nsw>)
; CHECK-NEXT: Loop %bb2: max backedge-taken count is 1
Index: llvm/test/Analysis/ScalarEvolution/extract-highbits-variablemask.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/extract-highbits-variablemask.ll
+++ llvm/test/Analysis/ScalarEvolution/extract-highbits-variablemask.ll
@@ -10,7 +10,7 @@
; CHECK-NEXT: %tmp1 = udiv i32 %val, %num
; CHECK-NEXT: --> (%val /u %num) U: full-set S: full-set
; CHECK-NEXT: %tmp2 = mul i32 %tmp1, %num
-; CHECK-NEXT: --> ((%val /u %num) * %num) U: full-set S: full-set
+; CHECK-NEXT: --> ((%val /u %num) * %num)<nuw> U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @div
;
%tmp1 = udiv i32 %val, %num
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -2397,6 +2397,17 @@
Ops[0]->isZero() && IsKnownNonNegative(Ops[1]))
Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
+ // both (udiv X, Y) * Y and Y * (udiv X, Y) are always NUW
+ if (Type == scMulExpr && !ScalarEvolution::hasFlags(Flags, SCEV::FlagNUW) &&
+ Ops.size() == 2) {
+ if (auto *UDiv = dyn_cast<SCEVUDivExpr>(Ops[0]))
+ if (UDiv->getOperand(1) == Ops[1])
+ Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
+ if (auto *UDiv = dyn_cast<SCEVUDivExpr>(Ops[1]))
+ if (UDiv->getOperand(1) == Ops[0])
+ Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
+ }
+
return Flags;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109786.372762.patch
Type: text/x-patch
Size: 4070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210915/44d1141a/attachment.bin>
More information about the llvm-commits
mailing list