[PATCH] D152068: [InstCombine] add overflow checking on AddSub `C-(X+C2) --> (C-C2)-X`
Kohei Asano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 3 09:56:48 PDT 2023
khei4 updated this revision to Diff 528115.
khei4 retitled this revision from "(WIP) [InstCombine] add overflow checking on AddSub" to "[InstCombine] add overflow checking on AddSub `C-(X+C2) --> (C-C2)-X`".
khei4 edited the summary of this revision.
khei4 added a reviewer: spatel.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152068/new/
https://reviews.llvm.org/D152068
Files:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1996,11 +1996,13 @@
// C-(X+C2) --> (C-C2)-X
if (match(Op1, m_Add(m_Value(X), m_ImmConstant(C2)))) {
- // c - c2 is overflow?
- bool HasNSW = false;
+ // C-C2, C-(X+C2), (X+C2) never overflow=> (C-C2)-X never overflow
BinaryOperator *Res =
BinaryOperator::CreateSub(ConstantExpr::getSub(C, C2), X);
- Res->setHasNoSignedWrap(HasNSW);
+ auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
+ Res->setHasNoSignedWrap(I.hasNoSignedWrap() &&
+ OBO1->hasNoUnsignedWrap() &&
+ willNotOverflowSignedSub(C, C2, *Res));
return Res;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152068.528115.patch
Type: text/x-patch
Size: 907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230603/96bc5884/attachment.bin>
More information about the llvm-commits
mailing list