| Issue |
164018
|
| Summary |
[HLSL] Condition operand of `select` implicitly truncates non-boolean vectors
|
| Labels |
HLSL
|
| Assignees |
|
| Reporter |
Icohedron
|
When the cond operand of `select` is given a vector that is not of boolean type, the vector implicitly gets truncated to its first element.
https://godbolt.org/z/7cP3xebfr
```hlsl
// compile args: -T lib_6_7 -Xclang -emit-llvm
export bool4 Foo(int4 a) {
return select(a, (true).xxxx, (false).xxxx);
}
export bool4 Bar(int4 a) {
return select(bool4(a), (true).xxxx, (false).xxxx);
}
```
What is observed (`Foo` and `Bar` are not equivalent):
```llvm
define noundef <4 x i1> @Foo(int vector[4])(<4 x i32> noundef %a) local_unnamed_addr #0 {
entry:
%0 = extractelement <4 x i32> %a, i64 0
%cast.vtrunc.not = icmp eq i32 %0, 0
%hlsl.select = select i1 %cast.vtrunc.not, <4 x i1> zeroinitializer, <4 x i1> splat (i1 true)
ret <4 x i1> %hlsl.select
}
define noundef <4 x i1> @Bar(int vector[4])(<4 x i32> noundef %a) local_unnamed_addr #0 {
entry:
%tobool = icmp ne <4 x i32> %a, zeroinitializer
ret <4 x i1> %tobool
}
```
What is expected (`Foo` and `Bar` should be equivalent):
```llvm
define noundef <4 x i1> @Foo(int vector[4])(<4 x i32> noundef %a) local_unnamed_addr #0 {
entry:
%tobool = icmp ne <4 x i32> %a, zeroinitializer
ret <4 x i1> %tobool
}
define noundef <4 x i1> @Bar(int vector[4])(<4 x i32> noundef %a) local_unnamed_addr #0 {
entry:
%tobool = icmp ne <4 x i32> %a, zeroinitializer
ret <4 x i1> %tobool
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs