[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
Wed Jul 18 12:01:56 PDT 2018


lebedev.ri added a comment.

I general looks good, i think.

Why do the testcases contain `nsw` attributes?
We transform anyway, and they aren't required, and don't affect the results.
I'd recommend dropping them. Unless there is a purpose?



================
Comment at: llvm/test/Transforms/InstSimplify/srem.ll:1
 ; RUN: opt < %s -instsimplify -S | FileCheck %s
 
----------------
The first line is missing, it should say it was produced with the tool.


================
Comment at: llvm/test/Transforms/InstSimplify/srem.ll:20
 ;
   %negx = sub nsw <2 x i32> zeroinitializer, %x
   %rem = srem <2 x i32> %negx, %x
----------------
I'd like to see more tests:
```
define <3 x i32> @negated_operand_vec_undef(<3 x i32> %x) {
  %negx = sub <3 x i32> <i32 0, i32 undef, i32 0>, %x
  %rem = srem <3 x i32> %negx, %x
  ret <3 x i32> %rem
}
define <2 x i32> @negated_operand_vec_nonsplat(<2 x i32> %x) {
  %negx = sub <2 x i32> <i32 0, 1>, %x ; not 0, don't fold
  %rem = srem <2 x i32> %negx, %x
  ret <2 x i32> %rem
}
```


https://reviews.llvm.org/D49423





More information about the llvm-commits mailing list