[PATCH] D49382: [InstrSimplify] fold sdiv if two operands are negatived and non-overflow
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 18 13:05:40 PDT 2018
lebedev.ri added a comment.
In general looks sane, but a few notes.
This fold does require `nsw` on `sub`, but i'm not seeing tests for that.
define i32 @negated_operand_bad(i32 %x) {
%negx = sub i32 0, %x ; not nsw
%div = sdiv i32 %negx, %x
ret i32 %div
}
define i32 @knownnegation_bad(i32 %x, i32 %y) {
%xy = sub nsw i32 %x, %y
%yx = sub i32 %y, %x ; not nsw
%div = sdiv i32 %xy, %yx
ret i32 %div
}
define i32 @knownnegation_bad(i32 %x, i32 %y) {
%xy = sub i32 %x, %y ; not nsw
%yx = sub nsw i32 %y, %x
%div = sdiv i32 %xy, %yx
ret i32 %div
}
define i32 @knownnegation_bad(i32 %x, i32 %y) {
%xy = sub i32 %x, %y ; not nsw
%yx = sub i32 %y, %x ; not nsw
%div = sdiv i32 %xy, %yx
ret i32 %div
}
================
Comment at: llvm/test/Transforms/InstSimplify/sdiv.ll:40
}
+
+define i32 @knownnegation_2(i32 %t) {
----------------
Same as with D49423, i'd like to see a bit more tests:
```
define <3 x i32> @negated_operand_vec_undef(<3 x i32> %x) {
%negx = sub nsw <3 x i32> <i32 0, i32 undef, i32 0>, %x
%rem = sdiv <3 x i32> %negx, %x
ret <3 x i32> %rem
}
define <2 x i32> @negated_operand_vec_nonsplat(<2 x i32> %x) {
%negx = sub nsw <2 x i32> <i32 0, 1>, %x ; not 0, don't fold
%rem = sdiv <2 x i32> %negx, %x
ret <2 x i32> %rem
}
```
https://reviews.llvm.org/D49382
More information about the llvm-commits
mailing list