[PATCH] D109786: [SCEV] (udiv X, Y) * Y is always NUW
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 14 14:02:55 PDT 2021
reames created this revision.
reames added reviewers: nikic, fhahn, mkazantsev, efriedma.
Herald added subscribers: bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.
Motivated by the removal done in D109782 <https://reviews.llvm.org/D109782>. This implements the correct flag part generically.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109786
Files:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/extract-highbits-variablemask.ll
llvm/test/Analysis/ScalarEvolution/mul.ll
Index: llvm/test/Analysis/ScalarEvolution/mul.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/ScalarEvolution/mul.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s "-passes=print<scalar-evolution>" -disable-output 2>&1 | FileCheck %s
+
+define i8 @test(i8 %x, i8 %y) {
+; CHECK-LABEL: 'test'
+; CHECK-NEXT: Classifying expressions for: @test
+; 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)<nuw> U: full-set S: full-set
+; CHECK-NEXT: Determining loop execution counts for: @test
+;
+ %udiv = udiv i8 %x, %y
+ %res = mul i8 %udiv, %y
+ ret i8 %res
+}
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,14 @@
Ops[0]->isZero() && IsKnownNonNegative(Ops[1]))
Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
+ // (udiv X, Y) * Y is always NUW
+ if (Type == scMulExpr && !ScalarEvolution::hasFlags(Flags, SCEV::FlagNUW) &&
+ Ops.size() == 2) {
+ auto *UDiv = dyn_cast<SCEVUDivExpr>(Ops[0]);
+ if (UDiv && UDiv->getNumOperands() == 2 && UDiv->getOperand(1) == Ops[1])
+ Flags = ScalarEvolution::setFlags(Flags, SCEV::FlagNUW);
+ }
+
return Flags;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109786.372560.patch
Type: text/x-patch
Size: 2220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210914/639252c5/attachment.bin>
More information about the llvm-commits
mailing list