[clang] [llvm] [DirectX] Add support for VectorReduce update Any\All to use it (PR #224745)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 6 09:54:24 PST 2026
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/224745
>From a521c09e28a78373011cb421a1825a5bce4aee8c Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlotfi at microsoft.com>
Date: Fri, 18 Sep 2026 16:53:21 -0400
Subject: [PATCH 1/2] [DirectX] Add support for VectorReduce update Any\All to
use it
resolves #224710
We added a custom scalarization for vector reduce or\and
W made the all and any intrinsics use the vector reduction
intrinsics
add tests to cover the 4 cases
---
.../Target/DirectX/DXILIntrinsicExpansion.cpp | 50 ++++++++++++++++++-
llvm/test/CodeGen/DirectX/LongVector/all.ll | 22 ++++++++
llvm/test/CodeGen/DirectX/LongVector/any.ll | 22 ++++++++
.../DirectX/LongVector/vector-reduce-and.ll | 10 ++++
.../DirectX/LongVector/vector-reduce-or.ll | 10 ++++
5 files changed, 112 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/DirectX/LongVector/all.ll
create mode 100644 llvm/test/CodeGen/DirectX/LongVector/any.ll
create mode 100644 llvm/test/CodeGen/DirectX/LongVector/vector-reduce-and.ll
create mode 100644 llvm/test/CodeGen/DirectX/LongVector/vector-reduce-or.ll
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index ab611e9e17966d..dbe02584e44b00 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -240,6 +240,9 @@ static bool isIntrinsicExpansion(Function &F) {
case Intrinsic::dx_load_input:
case Intrinsic::dx_store_output:
return true;
+ case Intrinsic::vector_reduce_and:
+ case Intrinsic::vector_reduce_or:
+ return F.getParent()->getTargetTriple().getOSVersion() < VersionTuple(6, 9);
case Intrinsic::dx_fdot:
return shouldExpandFloatDotIntrinsic(F);
case Intrinsic::dx_resource_load_rawbuffer:
@@ -397,6 +400,23 @@ static Value *expandVecReduceAdd(CallInst *Orig, Intrinsic::ID IntrinsicId) {
return Sum;
}
+static Value *expandVecReduceAndOr(CallInst *Orig, Intrinsic::ID IntrinsicId) {
+ assert(IntrinsicId == Intrinsic::vector_reduce_and ||
+ IntrinsicId == Intrinsic::vector_reduce_or);
+
+ IRBuilder<> Builder(Orig);
+ Value *X = Orig->getArgOperand(0);
+ auto *XVec = cast<FixedVectorType>(X->getType());
+ Value *Result = Builder.CreateExtractElement(X, static_cast<uint64_t>(0));
+ for (unsigned I = 1; I < XVec->getNumElements(); ++I) {
+ Value *Elt = Builder.CreateExtractElement(X, I);
+ Result = IntrinsicId == Intrinsic::vector_reduce_or
+ ? Builder.CreateOr(Result, Elt)
+ : Builder.CreateAnd(Result, Elt);
+ }
+ return Result;
+}
+
static Value *expandAbs(CallInst *Orig) {
Value *X = Orig->getOperand(0);
IRBuilder<> Builder(Orig);
@@ -593,8 +613,8 @@ static Value *expandIsFPClass(CallInst *Orig) {
}
}
-static Value *expandAnyOrAllIntrinsic(CallInst *Orig,
- Intrinsic::ID IntrinsicId) {
+static Value *expandAnyOrAllIntrinsicScalarized(CallInst *Orig,
+ Intrinsic::ID IntrinsicId) {
Value *X = Orig->getOperand(0);
IRBuilder<> Builder(Orig);
Type *Ty = X->getType();
@@ -634,6 +654,28 @@ static Value *expandAnyOrAllIntrinsic(CallInst *Orig,
return Result;
}
+// This version of Any/All starting with SM6.9 uses the vector_reduce_*
+// intrinsics
+// when possible for better performance.
+static Value *expandAnyOrAllIntrinsic(CallInst *Orig,
+ Intrinsic::ID IntrinsicId) {
+ Value *X = Orig->getArgOperand(0);
+ Type *Ty = X->getType();
+ Type *EltTy = Ty->getScalarType();
+ if (!Ty->isVectorTy() ||
+ Orig->getModule()->getTargetTriple().getOSVersion() < VersionTuple(6, 9))
+ return expandAnyOrAllIntrinsicScalarized(Orig, IntrinsicId);
+
+ IRBuilder<> Builder(Orig);
+ Value *Cond = EltTy->isFloatingPointTy()
+ ? Builder.CreateFCmpUNE(X, Constant::getNullValue(Ty))
+ : Builder.CreateICmpNE(X, Constant::getNullValue(Ty));
+ Intrinsic::ID ReductionId = IntrinsicId == Intrinsic::dx_any
+ ? Intrinsic::vector_reduce_or
+ : Intrinsic::vector_reduce_and;
+ return Builder.CreateIntrinsic(Builder.getInt1Ty(), ReductionId, {Cond});
+}
+
static Value *expandLogIntrinsic(CallInst *Orig,
float LogConstVal = numbers::ln2f) {
Value *X = Orig->getOperand(0);
@@ -1325,6 +1367,10 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) {
case Intrinsic::dx_any:
Result = expandAnyOrAllIntrinsic(Orig, IntrinsicId);
break;
+ case Intrinsic::vector_reduce_and:
+ case Intrinsic::vector_reduce_or:
+ Result = expandVecReduceAndOr(Orig, IntrinsicId);
+ break;
case Intrinsic::dx_uclamp:
case Intrinsic::dx_sclamp:
case Intrinsic::dx_nclamp:
diff --git a/llvm/test/CodeGen/DirectX/LongVector/all.ll b/llvm/test/CodeGen/DirectX/LongVector/all.ll
new file mode 100644
index 00000000000000..8f48f25658e819
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/LongVector/all.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
+; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
+
+; CHECK-LABEL: define i1 @test_all(
+; CHECK-SCALAR-COUNT-17: icmp ne i32 {{.*}}, 0
+; CHECK-SCALAR-COUNT-16: and i1
+; CHECK-VECTOR: [[CMP:%.*]] = icmp ne <17 x i32> %a, zeroinitializer
+; CHECK-VECTOR: call i1 @llvm.vector.reduce.and.v17i1(<17 x i1> [[CMP]])
+define i1 @test_all(<17 x i32> %a) {
+ %result = call i1 @llvm.dx.all.v17i32(<17 x i32> %a)
+ ret i1 %result
+}
+
+; CHECK-LABEL: define i1 @test_all_float(
+; CHECK-SCALAR-COUNT-17: fcmp une float {{.*}}, 0.000000e+00
+; CHECK-SCALAR-COUNT-16: and i1
+; CHECK-VECTOR: [[CMP:%.*]] = fcmp une <17 x float> %a, zeroinitializer
+; CHECK-VECTOR: call i1 @llvm.vector.reduce.and.v17i1(<17 x i1> [[CMP]])
+define i1 @test_all_float(<17 x float> %a) {
+ %result = call i1 @llvm.dx.all.v17f32(<17 x float> %a)
+ ret i1 %result
+}
diff --git a/llvm/test/CodeGen/DirectX/LongVector/any.ll b/llvm/test/CodeGen/DirectX/LongVector/any.ll
new file mode 100644
index 00000000000000..59cd872e7b34a5
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/LongVector/any.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
+; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
+
+; CHECK-LABEL: define i1 @test_any(
+; CHECK-SCALAR-COUNT-17: icmp ne i32 {{.*}}, 0
+; CHECK-SCALAR-COUNT-16: or i1
+; CHECK-VECTOR: [[CMP:%.*]] = icmp ne <17 x i32> %a, zeroinitializer
+; CHECK-VECTOR: call i1 @llvm.vector.reduce.or.v17i1(<17 x i1> [[CMP]])
+define i1 @test_any(<17 x i32> %a) {
+ %result = call i1 @llvm.dx.any.v17i32(<17 x i32> %a)
+ ret i1 %result
+}
+
+; CHECK-LABEL: define i1 @test_any_float(
+; CHECK-SCALAR-COUNT-17: fcmp une float {{.*}}, 0.000000e+00
+; CHECK-SCALAR-COUNT-16: or i1
+; CHECK-VECTOR: [[CMP:%.*]] = fcmp une <17 x float> %a, zeroinitializer
+; CHECK-VECTOR: call i1 @llvm.vector.reduce.or.v17i1(<17 x i1> [[CMP]])
+define i1 @test_any_float(<17 x float> %a) {
+ %result = call i1 @llvm.dx.any.v17f32(<17 x float> %a)
+ ret i1 %result
+}
diff --git a/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-and.ll b/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-and.ll
new file mode 100644
index 00000000000000..fc7912cfbe810a
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-and.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
+; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
+
+; CHECK-LABEL: define i32 @test_vector_reduce_and(
+; CHECK-SCALAR-COUNT-16: and i32
+; CHECK-VECTOR: call i32 @llvm.vector.reduce.and.v17i32(<17 x i32> %a)
+define i32 @test_vector_reduce_and(<17 x i32> %a) {
+ %result = call i32 @llvm.vector.reduce.and.v17i32(<17 x i32> %a)
+ ret i32 %result
+}
diff --git a/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-or.ll b/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-or.ll
new file mode 100644
index 00000000000000..0eb6aad44f04f9
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/LongVector/vector-reduce-or.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
+; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
+
+; CHECK-LABEL: define i32 @test_vector_reduce_or(
+; CHECK-SCALAR-COUNT-16: or i32
+; CHECK-VECTOR: call i32 @llvm.vector.reduce.or.v17i32(<17 x i32> %a)
+define i32 @test_vector_reduce_or(<17 x i32> %a) {
+ %result = call i32 @llvm.vector.reduce.or.v17i32(<17 x i32> %a)
+ ret i32 %result
+}
>From e79eea239605ee7c73345f7f547b2fa989b1d905 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlotfi at microsoft.com>
Date: Fri, 18 Sep 2026 19:10:50 -0400
Subject: [PATCH 2/2] Move all\any into the HLSL header
---
clang/include/clang/Basic/Builtins.td | 12 -
clang/include/clang/Basic/HLSLIntrinsics.td | 34 +-
clang/lib/CodeGen/CGHLSLBuiltins.cpp | 17 +-
clang/lib/CodeGen/CGHLSLRuntime.h | 3 -
.../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 10 +
clang/lib/Sema/SemaHLSL.cpp | 8 -
.../CodeGenDirectX/unsupported_intrinsic.hlsl | 9 -
clang/test/CodeGenHLSL/builtins/all.hlsl | 248 ++++-----------
clang/test/CodeGenHLSL/builtins/any.hlsl | 297 +++++-------------
clang/test/CodeGenHLSL/builtins/clip.hlsl | 12 +-
clang/test/SemaHLSL/BuiltIns/all-errors.hlsl | 12 -
clang/test/SemaHLSL/BuiltIns/any-errors.hlsl | 12 -
llvm/include/llvm/IR/IntrinsicsDirectX.td | 6 -
.../Target/DirectX/DXILIntrinsicExpansion.cpp | 69 ----
llvm/test/CodeGen/DirectX/LongVector/all.ll | 22 --
llvm/test/CodeGen/DirectX/LongVector/any.ll | 22 --
llvm/test/CodeGen/DirectX/all.ll | 83 -----
llvm/test/CodeGen/DirectX/any.ll | 113 -------
llvm/test/CodeGen/DirectX/discard.ll | 2 +-
19 files changed, 185 insertions(+), 806 deletions(-)
delete mode 100644 clang/test/CodeGenDirectX/unsupported_intrinsic.hlsl
delete mode 100644 clang/test/SemaHLSL/BuiltIns/all-errors.hlsl
delete mode 100644 clang/test/SemaHLSL/BuiltIns/any-errors.hlsl
delete mode 100644 llvm/test/CodeGen/DirectX/LongVector/all.ll
delete mode 100644 llvm/test/CodeGen/DirectX/LongVector/any.ll
delete mode 100644 llvm/test/CodeGen/DirectX/all.ll
delete mode 100644 llvm/test/CodeGen/DirectX/any.ll
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index d4d2393240433d..3689888b3d4067 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5579,12 +5579,6 @@ def HLSLResourceGetStride : LangBuiltin<"HLSL_LANG"> {
let Prototype = "void(__hlsl_resource_t, uint32_t&)";
}
-def HLSLAll : LangBuiltin<"HLSL_LANG"> {
- let Spellings = ["__builtin_hlsl_all"];
- let Attributes = [NoThrow, Const];
- let Prototype = "bool(...)";
-}
-
def HLSLAnd : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_and"];
let Attributes = [NoThrow, Const];
@@ -5597,12 +5591,6 @@ def HLSLOr : LangBuiltin<"HLSL_LANG"> {
let Prototype = "void(...)";
}
-def HLSLAny : LangBuiltin<"HLSL_LANG"> {
- let Spellings = ["__builtin_hlsl_any"];
- let Attributes = [NoThrow, Const];
- let Prototype = "bool(...)";
-}
-
def HLSLAsDouble : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_asdouble"];
let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td
index dc1b6dded264c5..364c89f374582f 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -381,16 +381,29 @@ values representing the result of unsigned 64-bit integer addition.
// Returns True if all components of the x parameter are non-zero;
// otherwise, false.
-def hlsl_all : HLSLOneArgBuiltin<"all", "__builtin_hlsl_all"> {
+def hlsl_all : HLSLBuiltin<"all"> {
let Doc = [{
\fn bool all(T x)
\brief Returns True if all components of the \a x parameter are non-zero;
otherwise, false.
\param x The input value.
}];
+ let ParamNames = ["V"];
+ let Body = "return V != 0;";
+ let Args = [Varying];
let ReturnType = BoolTy;
let VaryingTypes = AllTypesWithBool;
- let VaryingMatDims = [];
+ let VaryingScalar = 1;
+}
+
+def hlsl_all_vector : HLSLBuiltin<"all"> {
+ let ParamNames = ["V"];
+ let DetailFunc = "all_impl";
+ let Args = [Varying];
+ let ReturnType = BoolTy;
+ let VaryingTypes = AllTypesWithBool;
+ let VaryingVecSizes = [2, 3, 4];
+ let VaryingLongVector = 1;
}
// Returns the boolean AND of two boolean scalars, vectors, or matrices.
@@ -405,16 +418,29 @@ produces a bool vector or matrix output.
// Returns True if any components of the x parameter are non-zero;
// otherwise, false.
-def hlsl_any : HLSLOneArgBuiltin<"any", "__builtin_hlsl_any"> {
+def hlsl_any : HLSLBuiltin<"any"> {
let Doc = [{
\fn bool any(T x)
\brief Returns True if any components of the \a x parameter are non-zero;
otherwise, false.
\param x The input value.
}];
+ let ParamNames = ["V"];
+ let Body = "return V != 0;";
+ let Args = [Varying];
let ReturnType = BoolTy;
let VaryingTypes = AllTypesWithBool;
- let VaryingMatDims = [];
+ let VaryingScalar = 1;
+}
+
+def hlsl_any_vector : HLSLBuiltin<"any"> {
+ let ParamNames = ["V"];
+ let DetailFunc = "any_impl";
+ let Args = [Varying];
+ let ReturnType = BoolTy;
+ let VaryingTypes = AllTypesWithBool;
+ let VaryingVecSizes = [2, 3, 4];
+ let VaryingLongVector = 1;
}
// Reinterprets a cast value (two 32-bit values) into a double.
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index be680b259b9039..9e407e4bfa0467 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -92,8 +92,7 @@ static Value *handleHlslClip(const CallExpr *E, CodeGenFunction *CGF) {
ElementCount::getFixed(VecTy->getNumElements()), FZeroConst);
auto *FCompInst = CGF->Builder.CreateFCmpOLT(Op0, FZeroConst);
CMP = CGF->Builder.CreateIntrinsic(
- CGF->Builder.getInt1Ty(), CGF->CGM.getHLSLRuntime().getAnyIntrinsic(),
- {FCompInst});
+ CGF->Builder.getInt1Ty(), Intrinsic::vector_reduce_or, {FCompInst});
} else {
CMP = CGF->Builder.CreateFCmpOLT(Op0, FZeroConst);
}
@@ -1205,13 +1204,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
LValue Stride = EmitLValue(E->getArg(1));
return emitBufferStride(this, E->getArg(0), Stride);
}
- case Builtin::BI__builtin_hlsl_all: {
- Value *Op0 = EmitScalarExpr(E->getArg(0));
- return Builder.CreateIntrinsic(
- /*ReturnType=*/llvm::Type::getInt1Ty(getLLVMContext()),
- CGM.getHLSLRuntime().getAllIntrinsic(), ArrayRef<Value *>{Op0}, nullptr,
- "hlsl.all");
- }
case Builtin::BI__builtin_hlsl_and: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
@@ -1222,13 +1214,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
Value *Op1 = EmitScalarExpr(E->getArg(1));
return Builder.CreateOr(Op0, Op1, "hlsl.or");
}
- case Builtin::BI__builtin_hlsl_any: {
- Value *Op0 = EmitScalarExpr(E->getArg(0));
- return Builder.CreateIntrinsic(
- /*ReturnType=*/llvm::Type::getInt1Ty(getLLVMContext()),
- CGM.getHLSLRuntime().getAnyIntrinsic(), ArrayRef<Value *>{Op0}, nullptr,
- "hlsl.any");
- }
case Builtin::BI__builtin_hlsl_asdouble:
return handleAsDoubleBuiltin(*this, E);
case Builtin::BI__builtin_hlsl_elementwise_clamp: {
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 17bb04fbc90e97..2d33267631944f 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -123,9 +123,6 @@ class CGHLSLRuntime {
//===----------------------------------------------------------------------===//
// Start of reserved area for HLSL intrinsic getters.
//===----------------------------------------------------------------------===//
-
- GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
- GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
GENERATE_HLSL_INTRINSIC_FUNCTION(FlattenedThreadIdInGroup,
flattened_thread_id_in_group)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 2a908239d471bf..5bcce0f68c3865 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -12,6 +12,16 @@
namespace hlsl {
namespace __detail {
+template <typename T, int N> constexpr bool all_impl(vector<T, N> V) {
+ return __builtin_reduce_and(
+ __builtin_convertvector(V != static_cast<T>(0), vector<bool, N>));
+}
+
+template <typename T, int N> constexpr bool any_impl(vector<T, N> V) {
+ return __builtin_reduce_or(
+ __builtin_convertvector(V != static_cast<T>(0), vector<bool, N>));
+}
+
template <typename T>
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
length_impl(T X) {
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index eb6fce49d87083..b783ec096f254c 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -4956,14 +4956,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
TheCall->setType(ArgTyA);
break;
}
- case Builtin::BI__builtin_hlsl_all:
- case Builtin::BI__builtin_hlsl_any: {
- if (SemaRef.checkArgCount(TheCall, 1))
- return true;
- if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
- return true;
- break;
- }
case Builtin::BI__builtin_hlsl_asdouble: {
if (SemaRef.checkArgCount(TheCall, 2))
return true;
diff --git a/clang/test/CodeGenDirectX/unsupported_intrinsic.hlsl b/clang/test/CodeGenDirectX/unsupported_intrinsic.hlsl
deleted file mode 100644
index fc4b449bebf10c..00000000000000
--- a/clang/test/CodeGenDirectX/unsupported_intrinsic.hlsl
+++ /dev/null
@@ -1,9 +0,0 @@
-// REQUIRES: directx-registered-target
-// RUN: not %clang_cc1 -triple dxilv1.3-unknown-shadermodel6.3-library \
-// RUN: -finclude-default-header -S -o - %s 2>&1 | FileCheck %s
-
-// CHECK: error: Unsupported intrinsic llvm.vector.reduce.and.v4i32 for DXIL lowering
-
-export int vecReduceAndTest(int4 vec) {
- return __builtin_reduce_and(vec);
-}
diff --git a/clang/test/CodeGenHLSL/builtins/all.hlsl b/clang/test/CodeGenHLSL/builtins/all.hlsl
index 24322b6ea18579..37a5e957b8a00e 100644
--- a/clang/test/CodeGenHLSL/builtins/all.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/all.hlsl
@@ -1,193 +1,73 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -fnative-half-type -fnative-int16-type \
-// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN: --check-prefixes=CHECK,NATIVE_HALF \
-// RUN: -DFNATTRS="hidden spir_func noundef" -DTARGET=spv
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -emit-llvm -disable-llvm-passes \
-// RUN: -o - | FileCheck %s --check-prefixes=CHECK \
-// RUN: -DFNATTRS="hidden spir_func noundef" -DTARGET=spv
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type \
-// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN: --check-prefixes=CHECK,NATIVE_HALF \
-// RUN: -DFNATTRS="hidden noundef" -DTARGET=dx
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
-// RUN: -o - | FileCheck %s --check-prefixes=CHECK \
-// RUN: -DFNATTRS="hidden noundef" -DTARGET=dx
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library \
+// RUN: %s -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s
-#ifdef __HLSL_ENABLE_16_BIT
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_int16_t(int16_t p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_int16_t2(int16_t2 p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_int16_t3(int16_t3 p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_int16_t4(int16_t4 p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_uint16_t(uint16_t p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_uint16_t2(uint16_t2 p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_uint16_t3(uint16_t3 p0) { return all(p0); }
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i16
-// NATIVE_HALF: ret i1 %hlsl.all
-bool test_all_uint16_t4(uint16_t4 p0) { return all(p0); }
-#endif // __HLSL_ENABLE_16_BIT
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_half{{.*}}(half
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une half {{.*}}, 0.000000e+00
+// CHECK: ret i1 [[CMP]]
+bool test_all_half(half value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.f16
-// NO_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_half(half p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2f16
-// NO_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_half2(half2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3f16
-// NO_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_half3(half3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4f16
-// NO_HALF: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_half4(half4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_half2{{.*}}(<2 x half>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <2 x half> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v2i1(<2 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_half2(half2 value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_float(float p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_float2(float2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_float3(float3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4f32
-// CHECK: ret i1 %hlsl.all
-bool test_all_float4(float4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_int16_t3{{.*}}(<3 x i16>
+// CHECK: [[CMP:%.*]] = icmp ne <3 x i16> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v3i1(<3 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_int16_t3(int16_t3 value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.f64
-// CHECK: ret i1 %hlsl.all
-bool test_all_double(double p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2f64
-// CHECK: ret i1 %hlsl.all
-bool test_all_double2(double2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3f64
-// CHECK: ret i1 %hlsl.all
-bool test_all_double3(double3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4f64
-// CHECK: ret i1 %hlsl.all
-bool test_all_double4(double4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_float4{{.*}}(<4 x float>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <4 x float> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_float4(float4 value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_int(int p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_int2(int2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_int3(int3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_int4(int4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_float17{{.*}}(<17 x float>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <17 x float> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v17i1(<17 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_float17(vector<float, 17> value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint(uint p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint2(uint2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint3(uint3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i32
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint4(uint4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_double2{{.*}}(<2 x double>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <2 x double> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v2i1(<2 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_double2(double2 value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_int64_t(int64_t p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_int64_t2(int64_t2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_int64_t3(int64_t3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_int64_t4(int64_t4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_int{{.*}}(i32
+// CHECK: [[CMP:%.*]] = icmp ne i32 {{.*}}, 0
+// CHECK: ret i1 [[CMP]]
+bool test_all_int(int value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint64_t(uint64_t p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint64_t2(uint64_t2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint64_t3(uint64_t3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i64
-// CHECK: ret i1 %hlsl.all
-bool test_all_uint64_t4(uint64_t4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_uint3{{.*}}(<3 x i32>
+// CHECK: [[CMP:%.*]] = icmp ne <3 x i32> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v3i1(<3 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_uint3(uint3 value) { return all(value); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.i1
-// CHECK: ret i1 %hlsl.all
-bool test_all_bool(bool p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v2i1
-// CHECK: ret i1 %hlsl.all
-bool test_all_bool2(bool2 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v3i1
-// CHECK: ret i1 %hlsl.all
-bool test_all_bool3(bool3 p0) { return all(p0); }
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.all = call i1 @llvm.[[TARGET]].all.v4i1
-// CHECK: ret i1 %hlsl.all
-bool test_all_bool4(bool4 p0) { return all(p0); }
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_int64_t4{{.*}}(<4 x i64>
+// CHECK: [[CMP:%.*]] = icmp ne <4 x i64> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_int64_t4(int64_t4 value) { return all(value); }
+
+// NOTE: Bools are i32s in HLSL so thats why you see the zext ops in the IR.
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_all_bool4{{.*}}(<4 x i1>
+// CHECK-SAME: noundef [[INPUT:%.*]])
+// CHECK: [[INPUT_EXT:%.*]] = zext <4 x i1> [[INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[INPUT_EXT]], ptr [[INPUT_ADDR:%.*]]
+// CHECK-NEXT: [[INPUT_RAW:%.*]] = load <4 x i32>, ptr [[INPUT_ADDR]]
+// CHECK-NEXT: [[WRAPPER_INPUT:%.*]] = icmp ne <4 x i32> [[INPUT_RAW]], zeroinitializer
+// CHECK-NEXT: [[WRAPPER_EXT:%.*]] = zext <4 x i1> [[WRAPPER_INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[WRAPPER_EXT]], ptr [[WRAPPER_ADDR:%.*]]
+// CHECK-NEXT: [[WRAPPER_RAW:%.*]] = load <4 x i32>, ptr [[WRAPPER_ADDR]]
+// CHECK-NEXT: [[HELPER_INPUT:%.*]] = icmp ne <4 x i32> [[WRAPPER_RAW]], zeroinitializer
+// CHECK-NEXT: [[HELPER_EXT:%.*]] = zext <4 x i1> [[HELPER_INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[HELPER_EXT]], ptr [[HELPER_ADDR:%.*]]
+// CHECK-NEXT: [[HELPER_RAW:%.*]] = load <4 x i32>, ptr [[HELPER_ADDR]]
+// CHECK-NEXT: [[REDUCE_INPUT:%.*]] = icmp ne <4 x i32> [[HELPER_RAW]], zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[REDUCE_INPUT]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_all_bool4(bool4 value) { return all(value); }
diff --git a/clang/test/CodeGenHLSL/builtins/any.hlsl b/clang/test/CodeGenHLSL/builtins/any.hlsl
index 404aa56b804e71..e4b83730035b61 100644
--- a/clang/test/CodeGenHLSL/builtins/any.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/any.hlsl
@@ -1,224 +1,73 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -fnative-half-type -fnative-int16-type \
-// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN: --check-prefixes=CHECK,NATIVE_HALF \
-// RUN: -DFNATTRS="hidden spir_func noundef" -DTARGET=spv
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: spirv-unknown-vulkan-library %s -fnative-int16-type -emit-llvm -disable-llvm-passes \
-// RUN: -o - | FileCheck %s --check-prefixes=CHECK \
-// RUN: -DFNATTRS="hidden spir_func noundef" -DTARGET=spv
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type \
-// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN: --check-prefixes=CHECK,NATIVE_HALF \
-// RUN: -DFNATTRS="hidden noundef" -DTARGET=dx
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN: dxil-pc-shadermodel6.3-library %s -fnative-int16-type -emit-llvm -disable-llvm-passes \
-// RUN: -o - | FileCheck %s --check-prefixes=CHECK \
-// RUN: -DFNATTRS="hidden noundef" -DTARGET=dx
-
-#ifdef __HLSL_ENABLE_16_BIT
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_int16_t(int16_t p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_int16_t2(int16_t2 p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_int16_t3(int16_t3 p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_int16_t4(int16_t4 p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_uint16_t(uint16_t p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_uint16_t2(uint16_t2 p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_uint16_t3(uint16_t3 p0) { return any(p0); }
-
-// NATIVE_HALF: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i16
-// NATIVE_HALF: ret i1 %hlsl.any
-bool test_any_uint16_t4(uint16_t4 p0) { return any(p0); }
-#endif // __HLSL_ENABLE_16_BIT
-
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.f16
-// NO_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_half(half p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2f16
-// NO_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_half2(half2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3f16
-// NO_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_half3(half3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// NATIVE_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4f16
-// NO_HALF: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_half4(half4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_float(float p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_float2(float2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_float3(float3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4f32
-// CHECK: ret i1 %hlsl.any
-bool test_any_float4(float4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.f64
-// CHECK: ret i1 %hlsl.any
-bool test_any_double(double p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2f64
-// CHECK: ret i1 %hlsl.any
-bool test_any_double2(double2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3f64
-// CHECK: ret i1 %hlsl.any
-bool test_any_double3(double3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4f64
-// CHECK: ret i1 %hlsl.any
-bool test_any_double4(double4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_int(int p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_int2(int2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_int3(int3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_int4(int4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint(uint p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint2(uint2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint3(uint3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i32
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint4(uint4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_int64_t(int64_t p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_int64_t2(int64_t2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_int64_t3(int64_t3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_int64_t4(int64_t4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint64_t(uint64_t p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint64_t2(uint64_t2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint64_t3(uint64_t3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i64
-// CHECK: ret i1 %hlsl.any
-bool test_any_uint64_t4(uint64_t4 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.i1
-// CHECK: ret i1 %hlsl.any
-bool test_any_bool(bool p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v2i1
-// CHECK: ret i1 %hlsl.any
-bool test_any_bool2(bool2 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v3i1
-// CHECK: ret i1 %hlsl.any
-bool test_any_bool3(bool3 p0) { return any(p0); }
-
-// CHECK: define [[FNATTRS]] i1 @
-// CHECK: %hlsl.any = call i1 @llvm.[[TARGET]].any.v4i1
-// CHECK: ret i1 %hlsl.any
-bool test_any_bool4(bool4 p0) { return any(p0); }
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library \
+// RUN: %s -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_half{{.*}}(half
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une half {{.*}}, 0.000000e+00
+// CHECK: ret i1 [[CMP]]
+bool test_any_half(half value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_half2{{.*}}(<2 x half>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <2 x half> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v2i1(<2 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_half2(half2 value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_int16_t3{{.*}}(<3 x i16>
+// CHECK: [[CMP:%.*]] = icmp ne <3 x i16> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v3i1(<3 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_int16_t3(int16_t3 value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_float4{{.*}}(<4 x float>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <4 x float> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_float4(float4 value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_float17{{.*}}(<17 x float>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <17 x float> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v17i1(<17 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_float17(vector<float, 17> value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_double2{{.*}}(<2 x double>
+// CHECK: [[CMP:%.*]] = fcmp {{.*}} une <2 x double> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v2i1(<2 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_double2(double2 value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_int{{.*}}(i32
+// CHECK: [[CMP:%.*]] = icmp ne i32 {{.*}}, 0
+// CHECK: ret i1 [[CMP]]
+bool test_any_int(int value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_uint3{{.*}}(<3 x i32>
+// CHECK: [[CMP:%.*]] = icmp ne <3 x i32> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v3i1(<3 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_uint3(uint3 value) { return any(value); }
+
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_int64_t4{{.*}}(<4 x i64>
+// CHECK: [[CMP:%.*]] = icmp ne <4 x i64> {{.*}}, zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[CMP]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_int64_t4(int64_t4 value) { return any(value); }
+
+// NOTE: Bools are i32s in HLSL so thats why you see the zext ops in the IR.
+// CHECK-LABEL: define hidden noundef i1 @{{.*}}test_any_bool4{{.*}}(<4 x i1>
+// CHECK-SAME: noundef [[INPUT:%.*]])
+// CHECK: [[INPUT_EXT:%.*]] = zext <4 x i1> [[INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[INPUT_EXT]], ptr [[INPUT_ADDR:%.*]]
+// CHECK-NEXT: [[INPUT_RAW:%.*]] = load <4 x i32>, ptr [[INPUT_ADDR]]
+// CHECK-NEXT: [[WRAPPER_INPUT:%.*]] = icmp ne <4 x i32> [[INPUT_RAW]], zeroinitializer
+// CHECK-NEXT: [[WRAPPER_EXT:%.*]] = zext <4 x i1> [[WRAPPER_INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[WRAPPER_EXT]], ptr [[WRAPPER_ADDR:%.*]]
+// CHECK-NEXT: [[WRAPPER_RAW:%.*]] = load <4 x i32>, ptr [[WRAPPER_ADDR]]
+// CHECK-NEXT: [[HELPER_INPUT:%.*]] = icmp ne <4 x i32> [[WRAPPER_RAW]], zeroinitializer
+// CHECK-NEXT: [[HELPER_EXT:%.*]] = zext <4 x i1> [[HELPER_INPUT]] to <4 x i32>
+// CHECK-NEXT: store <4 x i32> [[HELPER_EXT]], ptr [[HELPER_ADDR:%.*]]
+// CHECK-NEXT: [[HELPER_RAW:%.*]] = load <4 x i32>, ptr [[HELPER_ADDR]]
+// CHECK-NEXT: [[REDUCE_INPUT:%.*]] = icmp ne <4 x i32> [[HELPER_RAW]], zeroinitializer
+// CHECK: [[REDUCE:%.*]] = call noundef i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[REDUCE_INPUT]])
+// CHECK: ret i1 [[REDUCE]]
+bool test_any_bool4(bool4 value) { return any(value); }
diff --git a/clang/test/CodeGenHLSL/builtins/clip.hlsl b/clang/test/CodeGenHLSL/builtins/clip.hlsl
index 40e9f7cd411e5a..638c40e1f19f49 100644
--- a/clang/test/CodeGenHLSL/builtins/clip.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/clip.hlsl
@@ -6,13 +6,13 @@ void test_clip_scalar(float Buf) {
// CHECK: define hidden void @{{.*}}test_clip_scalar{{.*}}(float {{.*}} [[VALP:%.*]])
// CHECK: [[LOAD:%.*]] = load float, ptr [[VALP]].addr
// CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt float [[LOAD]], 0.000000e+00
- // CHECK-NO: call i1 @llvm.dx.any
+ // CHECK-NO: call i1 @llvm.vector.reduce.or
// CHECK-NEXT: call void @llvm.dx.discard(i1 [[FCMP]])
//
// SPIRV: define hidden spir_func void @{{.*}}test_clip_scalar{{.*}}(float {{.*}} [[VALP:%.*]])
// SPIRV: [[LOAD:%.*]] = load float, ptr [[VALP]].addr
// SPIRV-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt float [[LOAD]], 0.000000e+00
- // SPIRV-NO: call i1 @llvm.spv.any
+ // SPIRV-NO: call i1 @llvm.vector.reduce.or
// SPIRV-NEXT: br i1 [[FCMP]], label %[[LTL:.*]], label %[[ENDL:.*]]
// SPIRV: [[LTL]]: ; preds = %entry
// SPIRV-NEXT: call void @llvm.spv.discard()
@@ -24,13 +24,13 @@ void test_clip_vector4(float4 Buf) {
// CHECK: define hidden void @{{.*}}test_clip_vector4{{.*}}(<4 x float> {{.*}} [[VALP:%.*]])
// CHECK: [[LOAD:%.*]] = load <4 x float>, ptr [[VALP]].addr
// CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt <4 x float> [[LOAD]], zeroinitializer
- // CHECK-NEXT: [[ANYC:%.*]] = call i1 @llvm.dx.any.v4i1(<4 x i1> [[FCMP]])
+ // CHECK-NEXT: [[ANYC:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[FCMP]])
// CHECK-NEXT: call void @llvm.dx.discard(i1 [[ANYC]])
//
// SPIRV: define hidden spir_func void @{{.*}}test_clip_vector4{{.*}}(<4 x float> {{.*}} [[VALP:%.*]])
// SPIRV: [[LOAD:%.*]] = load <4 x float>, ptr [[VALP]].addr
// SPIRV-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt <4 x float> [[LOAD]], zeroinitializer
- // SPIRV-NEXT: [[ANYC:%.*]] = call i1 @llvm.spv.any.v4i1(<4 x i1> [[FCMP]])
+ // SPIRV-NEXT: [[ANYC:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[FCMP]])
// SPIRV-NEXT: br i1 [[ANYC]], label %[[LTL:.*]], label %[[ENDL:.*]]
// SPIRV: [[LTL]]: ; preds = %entry
// SPIRV-NEXT: call void @llvm.spv.discard()
@@ -42,13 +42,13 @@ void test_clip_vector5(vector<float, 5> Buf) {
// CHECK: define hidden void @{{.*}}test_clip_vector5{{.*}}(<5 x float> {{.*}} [[VALP:%.*]])
// CHECK: [[LOAD:%.*]] = load <5 x float>, ptr [[VALP]].addr
// CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt <5 x float> [[LOAD]], zeroinitializer
- // CHECK-NEXT: [[ANYC:%.*]] = call i1 @llvm.dx.any.v5i1(<5 x i1> [[FCMP]])
+ // CHECK-NEXT: [[ANYC:%.*]] = call i1 @llvm.vector.reduce.or.v5i1(<5 x i1> [[FCMP]])
// CHECK-NEXT: call void @llvm.dx.discard(i1 [[ANYC]])
//
// SPIRV: define hidden spir_func void @{{.*}}test_clip_vector5{{.*}}(<5 x float> {{.*}} [[VALP:%.*]])
// SPIRV: [[LOAD:%.*]] = load <5 x float>, ptr [[VALP]].addr
// SPIRV-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt <5 x float> [[LOAD]], zeroinitializer
- // SPIRV-NEXT: [[ANYC:%.*]] = call i1 @llvm.spv.any.v5i1(<5 x i1> [[FCMP]])
+ // SPIRV-NEXT: [[ANYC:%.*]] = call i1 @llvm.vector.reduce.or.v5i1(<5 x i1> [[FCMP]])
// SPIRV-NEXT: br i1 [[ANYC]], label %[[LTL:.*]], label %[[ENDL:.*]]
// SPIRV: [[LTL]]: ; preds = %entry
// SPIRV-NEXT: call void @llvm.spv.discard()
diff --git a/clang/test/SemaHLSL/BuiltIns/all-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/all-errors.hlsl
deleted file mode 100644
index 5e00428de0c82e..00000000000000
--- a/clang/test/SemaHLSL/BuiltIns/all-errors.hlsl
+++ /dev/null
@@ -1,12 +0,0 @@
-
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
-
-bool test_too_few_arg() {
- return __builtin_hlsl_all();
- // expected-error at -1 {{too few arguments to function call, expected 1, have 0}}
-}
-
-bool test_too_many_arg(float2 p0) {
- return __builtin_hlsl_all(p0, p0);
- // expected-error at -1 {{too many arguments to function call, expected 1, have 2}}
-}
diff --git a/clang/test/SemaHLSL/BuiltIns/any-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/any-errors.hlsl
deleted file mode 100644
index 6210c998d8e2dd..00000000000000
--- a/clang/test/SemaHLSL/BuiltIns/any-errors.hlsl
+++ /dev/null
@@ -1,12 +0,0 @@
-
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
-
-bool test_too_few_arg() {
- return __builtin_hlsl_any();
- // expected-error at -1 {{too few arguments to function call, expected 1, have 0}}
-}
-
-bool test_too_many_arg(float2 p0) {
- return __builtin_hlsl_any(p0, p0);
- // expected-error at -1 {{too many arguments to function call, expected 1, have 2}}
-}
diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td b/llvm/include/llvm/IR/IntrinsicsDirectX.td
index 6970dd4b1c8fcf..d534e156c2e7be 100644
--- a/llvm/include/llvm/IR/IntrinsicsDirectX.td
+++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td
@@ -243,12 +243,6 @@ let TargetPrefix = "dx" in {
// Cast between target extension handle types and dxil-style opaque handles
def int_dx_resource_casthandle : Intrinsic<[llvm_any_ty], [llvm_any_ty]>;
- def int_dx_all
- : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], [IntrNoMem]>;
-
- def int_dx_any
- : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], [IntrNoMem]>;
-
def int_dx_asdouble
: DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_double_ty>],
[llvm_anyint_ty, LLVMMatchType<0>],
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index dbe02584e44b00..d2613d92a23a63 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -219,8 +219,6 @@ static bool isIntrinsicExpansion(Function &F) {
case Intrinsic::log10:
case Intrinsic::pow:
case Intrinsic::powi:
- case Intrinsic::dx_all:
- case Intrinsic::dx_any:
case Intrinsic::dx_uclamp:
case Intrinsic::dx_sclamp:
case Intrinsic::dx_nclamp:
@@ -613,69 +611,6 @@ static Value *expandIsFPClass(CallInst *Orig) {
}
}
-static Value *expandAnyOrAllIntrinsicScalarized(CallInst *Orig,
- Intrinsic::ID IntrinsicId) {
- Value *X = Orig->getOperand(0);
- IRBuilder<> Builder(Orig);
- Type *Ty = X->getType();
- Type *EltTy = Ty->getScalarType();
-
- auto ApplyOp = [&Builder](Intrinsic::ID IntrinsicId, Value *Result,
- Value *Elt) {
- if (IntrinsicId == Intrinsic::dx_any)
- return Builder.CreateOr(Result, Elt);
- assert(IntrinsicId == Intrinsic::dx_all);
- return Builder.CreateAnd(Result, Elt);
- };
-
- Value *Result = nullptr;
- if (!Ty->isVectorTy()) {
- Result = EltTy->isFloatingPointTy()
- ? Builder.CreateFCmpUNE(X, ConstantFP::get(EltTy, 0))
- : Builder.CreateICmpNE(X, ConstantInt::get(EltTy, 0));
- } else {
- auto *XVec = dyn_cast<FixedVectorType>(Ty);
- Value *Cond =
- EltTy->isFloatingPointTy()
- ? Builder.CreateFCmpUNE(
- X, ConstantVector::getSplat(
- ElementCount::getFixed(XVec->getNumElements()),
- ConstantFP::get(EltTy, 0)))
- : Builder.CreateICmpNE(
- X, ConstantVector::getSplat(
- ElementCount::getFixed(XVec->getNumElements()),
- ConstantInt::get(EltTy, 0)));
- Result = Builder.CreateExtractElement(Cond, (uint64_t)0);
- for (unsigned I = 1; I < XVec->getNumElements(); I++) {
- Value *Elt = Builder.CreateExtractElement(Cond, I);
- Result = ApplyOp(IntrinsicId, Result, Elt);
- }
- }
- return Result;
-}
-
-// This version of Any/All starting with SM6.9 uses the vector_reduce_*
-// intrinsics
-// when possible for better performance.
-static Value *expandAnyOrAllIntrinsic(CallInst *Orig,
- Intrinsic::ID IntrinsicId) {
- Value *X = Orig->getArgOperand(0);
- Type *Ty = X->getType();
- Type *EltTy = Ty->getScalarType();
- if (!Ty->isVectorTy() ||
- Orig->getModule()->getTargetTriple().getOSVersion() < VersionTuple(6, 9))
- return expandAnyOrAllIntrinsicScalarized(Orig, IntrinsicId);
-
- IRBuilder<> Builder(Orig);
- Value *Cond = EltTy->isFloatingPointTy()
- ? Builder.CreateFCmpUNE(X, Constant::getNullValue(Ty))
- : Builder.CreateICmpNE(X, Constant::getNullValue(Ty));
- Intrinsic::ID ReductionId = IntrinsicId == Intrinsic::dx_any
- ? Intrinsic::vector_reduce_or
- : Intrinsic::vector_reduce_and;
- return Builder.CreateIntrinsic(Builder.getInt1Ty(), ReductionId, {Cond});
-}
-
static Value *expandLogIntrinsic(CallInst *Orig,
float LogConstVal = numbers::ln2f) {
Value *X = Orig->getOperand(0);
@@ -1363,10 +1298,6 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) {
case Intrinsic::powi:
Result = expandPowIntrinsic(Orig, IntrinsicId);
break;
- case Intrinsic::dx_all:
- case Intrinsic::dx_any:
- Result = expandAnyOrAllIntrinsic(Orig, IntrinsicId);
- break;
case Intrinsic::vector_reduce_and:
case Intrinsic::vector_reduce_or:
Result = expandVecReduceAndOr(Orig, IntrinsicId);
diff --git a/llvm/test/CodeGen/DirectX/LongVector/all.ll b/llvm/test/CodeGen/DirectX/LongVector/all.ll
deleted file mode 100644
index 8f48f25658e819..00000000000000
--- a/llvm/test/CodeGen/DirectX/LongVector/all.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
-; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
-
-; CHECK-LABEL: define i1 @test_all(
-; CHECK-SCALAR-COUNT-17: icmp ne i32 {{.*}}, 0
-; CHECK-SCALAR-COUNT-16: and i1
-; CHECK-VECTOR: [[CMP:%.*]] = icmp ne <17 x i32> %a, zeroinitializer
-; CHECK-VECTOR: call i1 @llvm.vector.reduce.and.v17i1(<17 x i1> [[CMP]])
-define i1 @test_all(<17 x i32> %a) {
- %result = call i1 @llvm.dx.all.v17i32(<17 x i32> %a)
- ret i1 %result
-}
-
-; CHECK-LABEL: define i1 @test_all_float(
-; CHECK-SCALAR-COUNT-17: fcmp une float {{.*}}, 0.000000e+00
-; CHECK-SCALAR-COUNT-16: and i1
-; CHECK-VECTOR: [[CMP:%.*]] = fcmp une <17 x float> %a, zeroinitializer
-; CHECK-VECTOR: call i1 @llvm.vector.reduce.and.v17i1(<17 x i1> [[CMP]])
-define i1 @test_all_float(<17 x float> %a) {
- %result = call i1 @llvm.dx.all.v17f32(<17 x float> %a)
- ret i1 %result
-}
diff --git a/llvm/test/CodeGen/DirectX/LongVector/any.ll b/llvm/test/CodeGen/DirectX/LongVector/any.ll
deleted file mode 100644
index 59cd872e7b34a5..00000000000000
--- a/llvm/test/CodeGen/DirectX/LongVector/any.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: llc -mtriple=dxil-pc-shadermodel6.8-library -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SCALAR
-; RUN: llc -mtriple=dxil-pc-shadermodel6.9-library -stop-before=dxil-op-lower -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-VECTOR
-
-; CHECK-LABEL: define i1 @test_any(
-; CHECK-SCALAR-COUNT-17: icmp ne i32 {{.*}}, 0
-; CHECK-SCALAR-COUNT-16: or i1
-; CHECK-VECTOR: [[CMP:%.*]] = icmp ne <17 x i32> %a, zeroinitializer
-; CHECK-VECTOR: call i1 @llvm.vector.reduce.or.v17i1(<17 x i1> [[CMP]])
-define i1 @test_any(<17 x i32> %a) {
- %result = call i1 @llvm.dx.any.v17i32(<17 x i32> %a)
- ret i1 %result
-}
-
-; CHECK-LABEL: define i1 @test_any_float(
-; CHECK-SCALAR-COUNT-17: fcmp une float {{.*}}, 0.000000e+00
-; CHECK-SCALAR-COUNT-16: or i1
-; CHECK-VECTOR: [[CMP:%.*]] = fcmp une <17 x float> %a, zeroinitializer
-; CHECK-VECTOR: call i1 @llvm.vector.reduce.or.v17i1(<17 x i1> [[CMP]])
-define i1 @test_any_float(<17 x float> %a) {
- %result = call i1 @llvm.dx.any.v17f32(<17 x float> %a)
- ret i1 %result
-}
diff --git a/llvm/test/CodeGen/DirectX/all.ll b/llvm/test/CodeGen/DirectX/all.ll
deleted file mode 100644
index 444672705a4101..00000000000000
--- a/llvm/test/CodeGen/DirectX/all.ll
+++ /dev/null
@@ -1,83 +0,0 @@
-; RUN: opt -S -passes=dxil-intrinsic-expansion,dxil-op-lower -mtriple=dxil-pc-shadermodel6.0-library < %s | FileCheck %s
-
-; Make sure dxil operation function calls for all are generated for float and half.
-
-; CHECK-LABEL: all_bool
-; CHECK: icmp ne i1 %{{.*}}, false
-define noundef i1 @all_bool(i1 noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.i1(i1 %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_int64_t
-; CHECK: icmp ne i64 %{{.*}}, 0
-define noundef i1 @all_int64_t(i64 noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.i64(i64 %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_int
-; CHECK: icmp ne i32 %{{.*}}, 0
-define noundef i1 @all_int(i32 noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.i32(i32 %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_int16_t
-; CHECK: icmp ne i16 %{{.*}}, 0
-define noundef i1 @all_int16_t(i16 noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.i16(i16 %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_double
-; CHECK: fcmp une double %{{.*}}, 0.000000e+00
-define noundef i1 @all_double(double noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.f64(double %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_float
-; CHECK: fcmp une float %{{.*}}, 0.000000e+00
-define noundef i1 @all_float(float noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.f32(float %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_half
-; CHECK: fcmp une half %{{.*}}, 0.000000e+00
-define noundef i1 @all_half(half noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.f16(half %p0)
- ret i1 %dx.all
-}
-
-; CHECK-LABEL: all_bool4
-; CHECK: icmp ne <4 x i1> %{{.*}}, zeroinitialize
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 0
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 1
-; CHECK: and i1 %{{.*}}, %{{.*}}
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 2
-; CHECK: and i1 %{{.*}}, %{{.*}}
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 3
-; CHECK: and i1 %{{.*}}, %{{.*}}
-define noundef i1 @all_bool4(<4 x i1> noundef %p0) {
-entry:
- %dx.all = call i1 @llvm.dx.all.v4i1(<4 x i1> %p0)
- ret i1 %dx.all
-}
-
-declare i1 @llvm.dx.all.v4i1(<4 x i1>)
-declare i1 @llvm.dx.all.i1(i1)
-declare i1 @llvm.dx.all.i16(i16)
-declare i1 @llvm.dx.all.i32(i32)
-declare i1 @llvm.dx.all.i64(i64)
-declare i1 @llvm.dx.all.f16(half)
-declare i1 @llvm.dx.all.f32(float)
-declare i1 @llvm.dx.all.f64(double)
diff --git a/llvm/test/CodeGen/DirectX/any.ll b/llvm/test/CodeGen/DirectX/any.ll
deleted file mode 100644
index c530a05992f36f..00000000000000
--- a/llvm/test/CodeGen/DirectX/any.ll
+++ /dev/null
@@ -1,113 +0,0 @@
-; RUN: opt -S -passes=dxil-intrinsic-expansion,dxil-op-lower -mtriple=dxil-pc-shadermodel6.0-library < %s | FileCheck %s
-
-; Make sure dxil operation function calls for any are generated for float and half.
-
-; CHECK-LABEL: any_bool
-; CHECK: icmp ne i1 %{{.*}}, false
-define noundef i1 @any_bool(i1 noundef %p0) {
-entry:
- %p0.addr = alloca i8, align 1
- %frombool = zext i1 %p0 to i8
- store i8 %frombool, ptr %p0.addr, align 1
- %0 = load i8, ptr %p0.addr, align 1
- %tobool = trunc i8 %0 to i1
- %dx.any = call i1 @llvm.dx.any.i1(i1 %tobool)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_int64_t
-; CHECK: icmp ne i64 %{{.*}}, 0
-define noundef i1 @any_int64_t(i64 noundef %p0) {
-entry:
- %p0.addr = alloca i64, align 8
- store i64 %p0, ptr %p0.addr, align 8
- %0 = load i64, ptr %p0.addr, align 8
- %dx.any = call i1 @llvm.dx.any.i64(i64 %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_int
-; CHECK: icmp ne i32 %{{.*}}, 0
-define noundef i1 @any_int(i32 noundef %p0) {
-entry:
- %p0.addr = alloca i32, align 4
- store i32 %p0, ptr %p0.addr, align 4
- %0 = load i32, ptr %p0.addr, align 4
- %dx.any = call i1 @llvm.dx.any.i32(i32 %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_int16_t
-; CHECK: icmp ne i16 %{{.*}}, 0
-define noundef i1 @any_int16_t(i16 noundef %p0) {
-entry:
- %p0.addr = alloca i16, align 2
- store i16 %p0, ptr %p0.addr, align 2
- %0 = load i16, ptr %p0.addr, align 2
- %dx.any = call i1 @llvm.dx.any.i16(i16 %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_double
-; CHECK: fcmp une double %{{.*}}, 0.000000e+00
-define noundef i1 @any_double(double noundef %p0) {
-entry:
- %p0.addr = alloca double, align 8
- store double %p0, ptr %p0.addr, align 8
- %0 = load double, ptr %p0.addr, align 8
- %dx.any = call i1 @llvm.dx.any.f64(double %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_float
-; CHECK: fcmp une float %{{.*}}, 0.000000e+00
-define noundef i1 @any_float(float noundef %p0) {
-entry:
- %p0.addr = alloca float, align 4
- store float %p0, ptr %p0.addr, align 4
- %0 = load float, ptr %p0.addr, align 4
- %dx.any = call i1 @llvm.dx.any.f32(float %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_half
-; CHECK: fcmp une half %{{.*}}, 0.000000e+00
-define noundef i1 @any_half(half noundef %p0) {
-entry:
- %p0.addr = alloca half, align 2
- store half %p0, ptr %p0.addr, align 2
- %0 = load half, ptr %p0.addr, align 2
- %dx.any = call i1 @llvm.dx.any.f16(half %0)
- ret i1 %dx.any
-}
-
-; CHECK-LABEL: any_bool4
-; CHECK: icmp ne <4 x i1> %extractvec, zeroinitialize
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 0
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 1
-; CHECK: or i1 %{{.*}}, %{{.*}}
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 2
-; CHECK: or i1 %{{.*}}, %{{.*}}
-; CHECK: extractelement <4 x i1> %{{.*}}, i64 3
-; CHECK: or i1 %{{.*}}, %{{.*}}
-define noundef i1 @any_bool4(<4 x i1> noundef %p0) {
-entry:
- %p0.addr = alloca i8, align 1
- %insertvec = shufflevector <4 x i1> %p0, <4 x i1> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
- %0 = bitcast <8 x i1> %insertvec to i8
- store i8 %0, ptr %p0.addr, align 1
- %load_bits = load i8, ptr %p0.addr, align 1
- %1 = bitcast i8 %load_bits to <8 x i1>
- %extractvec = shufflevector <8 x i1> %1, <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
- %dx.any = call i1 @llvm.dx.any.v4i1(<4 x i1> %extractvec)
- ret i1 %dx.any
-}
-
-declare i1 @llvm.dx.any.v4i1(<4 x i1>)
-declare i1 @llvm.dx.any.i1(i1)
-declare i1 @llvm.dx.any.i16(i16)
-declare i1 @llvm.dx.any.i32(i32)
-declare i1 @llvm.dx.any.i64(i64)
-declare i1 @llvm.dx.any.f16(half)
-declare i1 @llvm.dx.any.f32(float)
-declare i1 @llvm.dx.any.f64(double)
diff --git a/llvm/test/CodeGen/DirectX/discard.ll b/llvm/test/CodeGen/DirectX/discard.ll
index 81a96d577ba1aa..dfbc151ce14974 100644
--- a/llvm/test/CodeGen/DirectX/discard.ll
+++ b/llvm/test/CodeGen/DirectX/discard.ll
@@ -23,7 +23,7 @@ entry:
define void @test_vector(<4 x float> noundef %p) #0 {
entry:
%0 = fcmp olt <4 x float> %p, zeroinitializer
- %1 = call i1 @llvm.dx.any.v4i1(<4 x i1> %0)
+ %1 = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> %0)
call void @llvm.dx.discard(i1 %1)
ret void
}
More information about the cfe-commits
mailing list