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-10-15 17:11:25 +08: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
2024-10-01 06:55:35 -07: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-10-17 08:48:08 +02:00
2024-09-19 16:16:38 +01:00
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
2024-10-11 05:26:03 -07:00
2024-09-08 10:10:16 +05:30
2024-10-11 05:26:03 -07:00
2024-10-17 10:32:55 -05:00
2024-10-21 17:00:41 -07: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-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
2024-09-05 12:53:57 +02:00
2024-09-19 16:16:38 +01:00
2024-09-19 16:16:38 +01: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-08-02 16:14:15 +02:00
2024-09-25 13:55:16 +04:00
2024-10-16 11:43:17 -07:00
2024-10-26 20:02:05 -07: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
2024-09-11 11:34:26 -07:00
2024-10-11 05:26:03 -07:00
2024-10-29 19:41:49 -07:00