[PATCH] D152068: (WIP) [InstCombine] add overflow checking on AddSub
Kohei Asano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 3 09:31:15 PDT 2023
khei4 created this revision.
khei4 added a reviewer: nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
khei4 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
proof: https://alive2.llvm.org/ce/z/W7RXmY
part of https://reviews.llvm.org/D146903
TODO: write description
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,11 @@
// 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);
+ // TODO: check C-(X+C2) and (X+C2)'s overflow
+ Res->setHasNoSignedWrap(willNotOverflowSignedSub(C, C2, *Res));
return Res;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152068.528114.patch
Type: text/x-patch
Size: 788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230603/0ae79acf/attachment.bin>
More information about the llvm-commits
mailing list