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