[PATCH] D49423: [InstSimplify] fold srem instruction if its two operands are negatived.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 01:28:03 PDT 2018


lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

OK, this looks good to me.
Please commit tests first, so the code change only changes the tests, not adds a new ones.



================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1112
 
+  // If the two operands are negatived, return 0.
+  if (isKnownNegation(Op0, Op1))
----------------
s/negatived/negated/? Not sure which is more correct in english.


================
Comment at: llvm/test/Transforms/InstSimplify/srem.ll:11
   ret i32 %rem
 }
 
----------------
One more test i didn't think of yet:
https://rise4fun.com/Alive/DplN
`isKnownNegation()` doesn't care about which operand came from which side.
In this case, it is ok, but in general `srem`/`sdiv` is not commutative.
It should be kept in mind, and at least one test should verify that we still fold this case properly.


https://reviews.llvm.org/D49423





More information about the llvm-commits mailing list