Yingwei Zheng
a77dedcacb
[InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280)
Previously we fold `div/rem X, C` into `poison` if any element of the
constant divisor `C` is zero or undef. However, it is incorrect when
threading udiv over an vector select:
https://alive2.llvm.org/ce/z/3Ninx5
```
define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {
%sel = select <2 x i1> %x, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 1>
%div = udiv <2 x i32> <i32 42, i32 -7>, %sel
ret <2 x i32> %div
}
```
In this case, `threadBinOpOverSelect` folds `udiv <i32 42, i32 -7>, <i32
-1, i32 -1>` and `udiv <i32 42, i32 -7>, <i32 0, i32 1>` into
`zeroinitializer` and `poison`, respectively. One solution is to
introduce a new flag indicating that we are threading over a vector
select. But it requires to modify both `InstSimplify` and
`ConstantFold`.
However, this optimization doesn't provide benefits to real-world
programs:
https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908
https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107
This patch moves the fold into InstCombine to avoid breaking numerous
existing tests.
Fixes #114191 and #113866 (only poison-safety issue).
2024-11-01 22:56:22 +08:00
..
2024-08-22 09:42:24 +00:00
2024-07-16 11:40:04 +02:00
2024-04-17 18:22:05 +09:00
2024-10-08 13:28:44 +01:00
2024-04-17 18:22:05 +09:00
2024-04-18 15:44:12 +09:00
2024-02-27 13:37:23 +00:00
2024-06-20 12:41:21 +02:00
2024-06-13 20:20:27 +01:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-11-01 22:56:22 +08:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-07-09 14:44:48 -07:00
2024-04-17 18:22:05 +09:00
2024-10-25 10:47:39 -07:00
2024-08-15 18:18:19 +02:00
2024-02-14 02:16:32 +03:00
2024-06-04 11:15:06 +02:00
2024-04-17 18:22:05 +09:00
2024-04-18 15:44:12 +09:00
2024-04-17 18:22:05 +09:00
2024-04-10 13:13:43 -05:00
2024-04-04 12:42:58 -05:00
2024-08-07 16:39:08 +02:00
2024-04-16 16:10:00 -05:00
2024-07-09 14:44:48 -07:00
2024-05-20 15:25:40 -05:00
2024-04-17 18:22:05 +09:00
2024-07-10 12:59:27 +08:00
2024-04-18 15:44:12 +09:00
2024-04-17 18:22:05 +09:00
2024-04-29 10:16:45 +01:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-05-31 08:55:59 +02:00
2024-06-25 14:28:13 +02:00
2024-06-04 08:31:03 +02:00
2024-04-11 12:48:52 +08:00
2024-04-17 18:22:05 +09:00
2024-07-15 09:26:03 +02:00
2024-11-01 22:56:22 +08:00
2024-08-18 20:55:05 +08:00
2024-04-17 18:22:05 +09:00
2024-10-14 14:08:12 +01:00
2024-08-06 10:30:04 +08:00
2024-07-03 09:02:31 +01:00
2024-10-14 11:37:30 +01:00
2024-03-20 12:43:00 +01:00
2024-04-17 18:22:05 +09:00
2024-05-21 08:06:34 +01:00
2024-04-17 18:22:05 +09:00
2024-04-17 18:22:05 +09:00
2024-06-24 12:01:46 +08:00
2024-04-15 13:54:09 +09:00
2024-05-30 08:36:44 +02:00
2024-02-27 13:37:23 +00:00
2024-02-27 13:37:23 +00:00
2024-04-17 18:22:05 +09:00