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
..
2022-03-12 17:26:40 +01:00
2024-10-15 17:11:25 +08:00
2022-03-28 20:57:52 -05:00
2024-10-01 11:45:32 -05:00
2024-10-17 20:28:47 -05:00
2024-10-27 16:14:13 -07:00
2024-08-29 14:12:02 +01:00
2023-01-20 22:38:17 +03:00
2024-10-01 06:55:35 -07:00
2022-02-02 06:54:20 +01:00
2024-11-01 22:56:22 +08:00
2024-10-08 15:55:10 +08:00
2024-09-05 16:11:00 +02:00
2024-06-28 14:51:41 -07:00
2024-10-17 08:48:08 +02:00
2024-09-19 16:16:38 +01:00
2024-03-18 10:34:11 +05:30
2024-10-11 05:26:03 -07:00
2024-08-20 16:05:39 +05:30
2024-10-25 10:02:40 -07:00
2024-10-28 10:59:53 -07:00
2024-09-19 16:16:38 +01:00
2022-12-12 09:24:04 -05:00
2024-10-11 05:26:03 -07:00
2022-06-05 01:07:51 -07:00
2024-09-08 10:10:16 +05:30
2021-10-15 09:18:57 -07:00
2024-10-11 05:26:03 -07:00
2024-05-29 16:09:59 -07:00
2024-01-14 00:53:28 -08:00
2024-04-23 10:39:03 -04:00
2022-12-03 13:55:56 -06:00
2024-10-17 10:32:55 -05:00
2023-01-03 15:07:03 +07:00
2024-10-21 17:00:41 -07:00
2022-02-06 22:18:35 -08:00
2022-10-14 09:47:26 +08:00
2024-10-15 17:11:25 +08:00
2024-09-30 23:15:18 +01:00
2024-10-11 05:26:03 -07:00
2024-10-16 07:21:10 -07:00
2024-10-17 16:20:43 +01:00
2024-06-14 15:07:27 +01:00
2024-10-16 06:40:10 -07:00
2024-09-25 11:13:56 -07:00
2024-09-25 11:13:56 -07:00
2024-09-25 11:13:56 -07:00
2023-06-26 13:48:10 +02:00
2024-09-05 12:53:57 +02:00
2024-09-19 16:16:38 +01:00
2024-04-24 08:52:25 +02:00
2024-09-19 16:16:38 +01:00
2019-01-19 08:50:56 +00:00
2024-10-11 05:26:03 -07:00
2024-09-07 11:21:20 -07:00
2024-10-15 23:07:16 +08:00
2024-07-30 08:41:52 -04:00
2024-08-02 16:14:15 +02:00
2024-10-24 08:07:13 +03:00
2024-06-28 14:30:47 +02:00
2024-08-02 16:14:15 +02:00
2023-10-27 08:59:21 -07:00
2023-08-30 10:05:06 +09:00
2024-09-25 13:55:16 +04:00
2024-04-30 12:23:31 -07:00
2024-06-07 11:37:49 -07:00
2024-06-17 09:28:09 +02:00
2024-10-16 11:43:17 -07:00
2023-03-14 18:56:07 -07:00
2023-08-03 10:36:57 +05:30
2022-02-02 06:54:20 +01:00
2024-10-26 20:02:05 -07:00
2023-10-17 15:24:44 +01:00
2024-10-25 11:24:47 -07:00
2024-08-12 13:28:26 +02:00
2024-09-02 11:56:40 +01:00
2022-04-03 12:54:54 -07:00
2024-09-11 11:34:26 -07:00
2024-07-04 09:47:59 +02:00
2024-05-28 16:09:53 +02:00
2024-10-11 05:26:03 -07:00
2024-10-29 19:41:49 -07:00
2024-01-19 22:24:13 -08:00