[PATCH] Added instruction combine to transform few more negative values addition to subtraction

Dinesh Dwivedi dinesh.d at samsung.com
Thu Jun 19 03:08:29 PDT 2014


fixed typo in previous comment

================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:951
@@ +950,3 @@
+    if (match(X, m_Xor(m_Value(Y), m_APInt(C1)))) {
+      if (match(Y, m_Or(m_Value(Z), m_APInt(C2))) && (*C2 == ~(*C1))) {
+        Value *NewAnd = Builder->CreateAnd(Z, *C1);
----------------
Dinesh Dwivedi wrote:
> Nick Lewycky wrote:
> > Optional: *C2 == ~(*C1) might be more efficient as !C2->intersects(*C1). It isn't, but in theory we could improve intersects to not compute an intermediate value (ie., it doesn't need to look at all the bits once it finds a pair are set in both).
> problem with intersects() is that it just ensure that same bit is not set in both C1 and C2 but does not ensure that if one but is set in one, it will not set in second.
> 
> We can compute xor and then check if result is all zero but I am not sure if that is more efficient than current code,
> it will sure reduce readability though.
Problem with intersects() is that it just ensure that same bit is not set in both C1 and C2 but does not ensure that if one bit is not set in one, it will be set in second.

http://reviews.llvm.org/D3733






More information about the llvm-commits mailing list