[llvm] [SelectionDAG] Do not build illegal nodes with users (PR #108573)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 08:00:41 PDT 2024
ErikHogeman wrote:
I managed to simplify our case down to this:
```
define i16 @func(i64 %arg, i64 %arg1, <2 x i16>* %_ptr, i16* %_ptr2) {
entry:
%i8 = load i16, i16* %_ptr2
%i9 = sub i16 0, %i8
%i10 = insertelement <2 x i16> undef, i16 %i9, i64 0
%i11 = insertelement <2 x i16> %i10, i16 %i9, i64 1
%i12 = sub <2 x i16> zeroinitializer, %i11
%i13 = extractelement <2 x i16> %i12, i64 0
%i14 = add i16 %i13, %i8
%i15 = insertelement <2 x i16> undef, i16 %i14, i64 0
%i16 = insertelement <2 x i16> undef, i16 %i8, i64 0
%i17 = extractelement <2 x i16> %i12, i64 1
%i18 = insertelement <2 x i16> %i16, i16 %i17, i64 1
%i19 = insertelement <2 x i16> %i16, i16 %i8, i64 1
%i20 = add <2 x i16> %i18, %i19
%i36 = icmp ne <2 x i16> %i20, %i12
%i37 = extractelement <2 x i1> %i36, i64 0
%i38 = extractelement <2 x i1> %i36, i64 1
%i39 = or i1 %i37, %i38
%i40 = icmp ne i16 %i13, 0
%i41 = or i1 %i39, %i40
%i43 = load i16, i16* %_ptr2
%i44 = sub i16 0, %i43
%i45 = select i1 %i41, i16 2, i16 %i44
ret i16 %i45
}
```
Running selection on this for x86_64 target, it will create the illegal i1 node. However, it happens during DAG combining just after type legalization, but the DAG combiner will only run LegalizeOp if it's AfterLegalizeDAG, and on top of that the illegal node is not added to the worklist again anyway since I didn't get other optimizations to trigger in such a way that this happens, so this prevents me from reproducing it. It's tricky since there's no way (at least I'm aware of?) to write selection DAG IR manually and run specific passes or transforms on it.
If there's any feedback about what I could try with the IR for an upstream target, or whether or not the change itself would be OK without a test, please let me know.
https://github.com/llvm/llvm-project/pull/108573
More information about the llvm-commits
mailing list