Skip to content

Instantly share code, notes, and snippets.

@aqjune
Created February 8, 2021 13:50
Show Gist options
  • Save aqjune/2ba8819bbe1229e4bab984807cef2c7a to your computer and use it in GitHub Desktop.
Save aqjune/2ba8819bbe1229e4bab984807cef2c7a to your computer and use it in GitHub Desktop.
Add nsw patch
diff --git a/ir/instr.cpp b/ir/instr.cpp
index 21e015a..4d93443 100644
--- a/ir/instr.cpp
+++ b/ir/instr.cpp
@@ -367,8 +367,17 @@ StateValue BinOp::toSMT(State &s) const {
case Add:
fn = [&](auto a, auto ap, auto b, auto bp) -> StateValue {
expr non_poison = true;
- if (flags & NSW)
+ if (flags & NSW) {
+ expr av, a_undefmask, a_undefvar, bv, b_undefmask, b_undefvar;
+ // If a and b are both inputs, strip undef mask away
+ if (Input::match(a, av, a_undefmask, a_undefvar) &&
+ Input::match(b, bv, b_undefmask, b_undefvar)) {
+ a = av;
+ b = bv;
+ non_poison &= a_undefmask && b_undefmask;
+ }
non_poison &= a.add_no_soverflow(b);
+ }
if (flags & NUW)
non_poison &= a.add_no_uoverflow(b);
return { a + b, move(non_poison) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment