Skip to content

Commit 07f29a3

Browse files
authored
Revert "[HLSL][DirectX] Emit convergence control tokens when targeting DirectX" (#193090)
This change appears to introduce complications when trying to do a full loop unroll that is exhibited here: https://github.com/llvm/llvm-project/actions/runs/24577221310/job/71865579618. This results in invalid DXIL as the unreachable branch is not correctly cleaned up. Initial leads look like this is because the instructions with convergence control tokens are still being used for analysis when they are within an unreachable branch. Reverts #188792
1 parent ee24b9e commit 07f29a3

73 files changed

Lines changed: 163 additions & 697 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,6 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
715715
Builder.CreatePHI(element->getType(), 2, "arrayinit.cur");
716716
currentElement->addIncoming(element, entryBB);
717717

718-
if (CGF.CGM.shouldEmitConvergenceTokens())
719-
CGF.ConvergenceTokenStack.push_back(CGF.emitConvergenceLoopToken(bodyBB));
720-
721718
// Emit the actual filler expression.
722719
{
723720
// C++1z [class.temporary]p5:
@@ -749,9 +746,6 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
749746
Builder.CreateCondBr(done, endBB, bodyBB);
750747
currentElement->addIncoming(nextElement, Builder.GetInsertBlock());
751748

752-
if (CGF.CGM.shouldEmitConvergenceTokens())
753-
CGF.ConvergenceTokenStack.pop_back();
754-
755749
CGF.EmitBlock(endBB);
756750
}
757751
}
@@ -1993,9 +1987,6 @@ void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
19931987
llvm::Value *element =
19941988
Builder.CreateInBoundsGEP(llvmElementType, begin, index);
19951989

1996-
if (CGF.CGM.shouldEmitConvergenceTokens())
1997-
CGF.ConvergenceTokenStack.push_back(CGF.emitConvergenceLoopToken(bodyBB));
1998-
19991990
// Prepare for a cleanup.
20001991
QualType::DestructionKind dtorKind = elementType.isDestructedType();
20011992
EHScopeStack::stable_iterator cleanup;
@@ -2043,9 +2034,6 @@ void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
20432034
llvm::BasicBlock *endBB = CGF.createBasicBlock("arrayinit.end");
20442035
Builder.CreateCondBr(done, endBB, bodyBB);
20452036

2046-
if (CGF.CGM.shouldEmitConvergenceTokens())
2047-
CGF.ConvergenceTokenStack.pop_back();
2048-
20492037
CGF.EmitBlock(endBB);
20502038

20512039
// Leave the partial-array cleanup if we entered one.

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
574574
Value *IndexOp = EmitScalarExpr(E->getArg(1));
575575

576576
llvm::Type *RetTy = ConvertType(E->getType());
577-
llvm::Function *IntrFn = llvm::Intrinsic::getOrInsertDeclaration(
578-
&CGM.getModule(),
579-
CGM.getHLSLRuntime().getCreateResourceGetPointerIntrinsic(),
580-
{RetTy, HandleOp->getType(), IndexOp->getType()});
581-
llvm::CallInst *CI = EmitRuntimeCall(IntrFn, {HandleOp, IndexOp});
582-
CI->setCallingConv(IntrFn->getCallingConv());
583-
return CI;
577+
return Builder.CreateIntrinsic(
578+
RetTy, CGM.getHLSLRuntime().getCreateResourceGetPointerIntrinsic(),
579+
ArrayRef<Value *>{HandleOp, IndexOp});
584580
}
585581
case Builtin::BI__builtin_hlsl_resource_sample: {
586582
Value *HandleOp = EmitScalarExpr(E->getArg(0));

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,8 @@ CGHLSLRuntime::emitDXILUserSemanticLoad(llvm::IRBuilder<> &B, llvm::Type *Type,
657657
llvm::PoisonValue::get(B.getInt32Ty())};
658658

659659
llvm::Intrinsic::ID IntrinsicID = llvm::Intrinsic::dx_load_input;
660-
661-
SmallVector<OperandBundleDef, 1> OB;
662-
if (auto *Token = getConvergenceToken(*B.GetInsertBlock())) {
663-
llvm::Value *bundleArgs[] = {Token};
664-
OB.emplace_back("convergencectrl", bundleArgs);
665-
}
666-
667-
llvm::Function *IntrFn = llvm::Intrinsic::getOrInsertDeclaration(
668-
B.GetInsertBlock()->getModule(), IntrinsicID, {Type});
669-
llvm::Value *Value = B.CreateCall(IntrFn, Args, OB, VariableName);
660+
llvm::Value *Value = B.CreateIntrinsic(/*ReturnType=*/Type, IntrinsicID, Args,
661+
nullptr, VariableName);
670662
return Value;
671663
}
672664

@@ -684,16 +676,7 @@ void CGHLSLRuntime::emitDXILUserSemanticStore(llvm::IRBuilder<> &B,
684676
Source};
685677

686678
llvm::Intrinsic::ID IntrinsicID = llvm::Intrinsic::dx_store_output;
687-
688-
SmallVector<OperandBundleDef, 1> OB;
689-
if (auto *Token = getConvergenceToken(*B.GetInsertBlock())) {
690-
llvm::Value *bundleArgs[] = {Token};
691-
OB.emplace_back("convergencectrl", bundleArgs);
692-
}
693-
694-
llvm::Function *IntrFn = llvm::Intrinsic::getOrInsertDeclaration(
695-
B.GetInsertBlock()->getModule(), IntrinsicID, {Source->getType()});
696-
B.CreateCall(IntrFn, Args, OB);
679+
B.CreateIntrinsic(/*ReturnType=*/CGM.VoidTy, IntrinsicID, Args, nullptr);
697680
}
698681

699682
llvm::Value *CGHLSLRuntime::emitUserSemanticLoad(

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5437,11 +5437,11 @@ class CodeGenFunction : public CodeGenTypeCache {
54375437
void maybeAttachRangeForLoad(llvm::LoadInst *Load, QualType Ty,
54385438
SourceLocation Loc);
54395439

5440+
private:
54405441
// Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
54415442
// as it's parent convergence instr.
54425443
llvm::ConvergenceControlInst *emitConvergenceLoopToken(llvm::BasicBlock *BB);
54435444

5444-
private:
54455445
// Adds a convergence_ctrl token with |ParentToken| as parent convergence
54465446
// instr to the call |Input|.
54475447
llvm::CallBase *addConvergenceControlToken(llvm::CallBase *Input);

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ class CodeGenModule : public CodeGenTypeCache {
18151815
bool shouldEmitConvergenceTokens() const {
18161816
// TODO: this should probably become unconditional once the controlled
18171817
// convergence becomes the norm.
1818-
return getTriple().isSPIRVLogical() || getTriple().isDXIL();
1818+
return getTriple().isSPIRVLogical();
18191819
}
18201820

18211821
void addUndefinedGlobalForTailCall(

clang/test/CodeGenDirectX/Builtins/dot2add.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ typedef half half2 __attribute__((ext_vector_type(2)));
88
// CHECK-LABEL: define float @test_dot2add(
99
// CHECK-SAME: <2 x half> noundef [[X:%.*]], <2 x half> noundef [[Y:%.*]], float noundef [[Z:%.*]]) #[[ATTR0:[0-9]+]] {
1010
// CHECK-NEXT: [[ENTRY:.*:]]
11-
// CHECK-NEXT: %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
1211
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca <2 x half>, align 2
1312
// CHECK-NEXT: [[Y_ADDR:%.*]] = alloca <2 x half>, align 2
1413
// CHECK-NEXT: [[Z_ADDR:%.*]] = alloca float, align 4

clang/test/CodeGenHLSL/BasicFeatures/ArrayReturn.hlsl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
typedef int Foo[2];
44

55
// CHECK-LABEL: define void {{.*}}boop{{.*}}(ptr dead_on_unwind noalias writable sret([2 x i32]) align 4 %agg.result)
6-
// CHECK: %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
76
// CHECK: [[G:%.*]] = alloca [2 x i32], align 4
87
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[G]], ptr align 4 {{.*}}, i32 8, i1 false)
98
// CHECK-NEXT: [[AIB:%.*]] = getelementptr inbounds [2 x i32], ptr %agg.result, i32 0, i32 0
109
// CHECK-NEXT: br label %arrayinit.body
1110
// CHECK: arrayinit.body:
1211
// CHECK-NEXT: [[AII:%.*]] = phi i32 [ 0, %entry ], [ %arrayinit.next, %arrayinit.body ]
13-
// CHECK-NEXT: %[[#CV_LOOP:]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %[[#C_ENTRY]]) ]
1412
// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i32, ptr [[AIB]], i32 [[AII]]
1513
// CHECK-NEXT: [[AI:%.*]] = getelementptr inbounds nuw [2 x i32], ptr [[G]], i32 0, i32 [[AII]]
1614
// CHECK-NEXT: [[Y:%.*]] = load i32, ptr [[AI]], align 4

0 commit comments

Comments
 (0)