[PATCH] D54532: [InstructionSimplify] Add support for saturating add/sub

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 18 07:04:11 PST 2018


spatel added inline comments.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:4925-4928
+    if (match(Op1, m_Zero()) || match(Op1, m_Undef()))
+      return Op0;
+    // 0 + X -> X, undef + X -> X
+    if (match(Op0, m_Zero()) || match(Op0, m_Undef()))
----------------
It's slightly better to return a constant when one of the operands is undef because that eliminates the use of a variable. That also matches the behavior of the subtracts. 

For sadd_sat, we can always return 0, and for uadd_sat, we can always return -1?


https://reviews.llvm.org/D54532





More information about the llvm-commits mailing list