[llvm] [RISCV] Insert a freeze before converting select to AND/OR. (PR #84232)
Björn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 06:42:28 PST 2024
bjope wrote:
I think we might have hit a similar problem in our testing, but involving foldBoolSelectToLogic in generic DAGCombiner.
The IR input to llc involved
```
%x = load i16, ptr @v_473, align 1, !tbaa !11
%cmp1 = icmp sgt i16 %x, 0
%sub = sub nsw i16 32767, %x
%cmp2 = icmp sgt i16 %x, %sub
%y = select i1 %cmp1, i1 %cmp2, i1 false
```
Resulting in a DAG with:
```
t6: i1 = setcc t4, Constant:i16<0>, setgt:ch
t8: i16 = sub nsw Constant:i16<32767>, t4
t9: i1 = setcc t4, t8, setgt:ch
t11: i1 = select t6, t9, Constant:i1<0>
```
that is combined into
```
t6: i1 = setcc t4, Constant:i16<0>, setgt:ch
t8: i16 = sub nsw Constant:i16<32767>, t4
t9: i1 = setcc t4, t8, setgt:ch
t23: i1 = and t6, t9
```
If t6 is false the result should be zero. But after folding to the and the result would become t9 instead.
But when t6 is false, it means that t4<=0. And for t4<0 then t8 is poison, so t9 could be poisonous.
https://github.com/llvm/llvm-project/pull/84232
More information about the llvm-commits
mailing list