Skip to content

Commit d1fb930

Browse files
committed
Revert "[AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (#71139)"
This reverts commit 32a3f2a. Reason: Broke the sanitizer buildbots. More details at 32a3f2a
1 parent 9d2903c commit d1fb930

File tree

3 files changed

+53
-81
lines changed

3 files changed

+53
-81
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,7 +5708,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
57085708
llvm::FunctionType *FTy = F->getFunctionType();
57095709

57105710
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
5711-
Value *ArgValue = EmitScalarOrConstFoldImmArg(ICEArguments, i, E);
5711+
Value *ArgValue;
5712+
// If this is a normal argument, just emit it as a scalar.
5713+
if ((ICEArguments & (1 << i)) == 0) {
5714+
ArgValue = EmitScalarExpr(E->getArg(i));
5715+
} else {
5716+
// If this is required to be a constant, constant fold it so that we
5717+
// know that the generated intrinsic gets a ConstantInt.
5718+
ArgValue = llvm::ConstantInt::get(
5719+
getLLVMContext(),
5720+
*E->getArg(i)->getIntegerConstantExpr(getContext()));
5721+
}
5722+
57125723
// If the intrinsic arg type is different from the builtin arg type
57135724
// we need to do a bit cast.
57145725
llvm::Type *PTy = FTy->getParamType(i);
@@ -8588,7 +8599,15 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
85888599
}
85898600
}
85908601

8591-
Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
8602+
if ((ICEArguments & (1 << i)) == 0) {
8603+
Ops.push_back(EmitScalarExpr(E->getArg(i)));
8604+
} else {
8605+
// If this is required to be a constant, constant fold it so that we know
8606+
// that the generated intrinsic gets a ConstantInt.
8607+
Ops.push_back(llvm::ConstantInt::get(
8608+
getLLVMContext(),
8609+
*E->getArg(i)->getIntegerConstantExpr(getContext())));
8610+
}
85928611
}
85938612

85948613
switch (BuiltinID) {
@@ -11075,7 +11094,15 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
1107511094
continue;
1107611095
}
1107711096
}
11078-
Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
11097+
if ((ICEArguments & (1 << i)) == 0) {
11098+
Ops.push_back(EmitScalarExpr(E->getArg(i)));
11099+
} else {
11100+
// If this is required to be a constant, constant fold it so that we know
11101+
// that the generated intrinsic gets a ConstantInt.
11102+
Ops.push_back(llvm::ConstantInt::get(
11103+
getLLVMContext(),
11104+
*E->getArg(i)->getIntegerConstantExpr(getContext())));
11105+
}
1107911106
}
1108011107

1108111108
auto SISDMap = ArrayRef(AArch64SISDIntrinsicMap);
@@ -13787,7 +13814,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1378713814
assert(Error == ASTContext::GE_None && "Should not codegen an error");
1378813815

1378913816
for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
13790-
Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
13817+
// If this is a normal argument, just emit it as a scalar.
13818+
if ((ICEArguments & (1 << i)) == 0) {
13819+
Ops.push_back(EmitScalarExpr(E->getArg(i)));
13820+
continue;
13821+
}
13822+
13823+
// If this is required to be a constant, constant fold it so that we know
13824+
// that the generated intrinsic gets a ConstantInt.
13825+
Ops.push_back(llvm::ConstantInt::get(
13826+
getLLVMContext(), *E->getArg(i)->getIntegerConstantExpr(getContext())));
1379113827
}
1379213828

1379313829
// These exist so that the builtin that takes an immediate can be bounds
@@ -17552,23 +17588,6 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order, Value *Scope,
1755217588
SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
1755317589
}
1755417590

17555-
llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
17556-
unsigned Idx,
17557-
const CallExpr *E) {
17558-
llvm::Value *Arg = nullptr;
17559-
if ((ICEArguments & (1 << Idx)) == 0) {
17560-
Arg = EmitScalarExpr(E->getArg(Idx));
17561-
} else {
17562-
// If this is required to be a constant, constant fold it so that we
17563-
// know that the generated intrinsic gets a ConstantInt.
17564-
std::optional<llvm::APSInt> Result =
17565-
E->getArg(Idx)->getIntegerConstantExpr(getContext());
17566-
assert(Result && "Expected argument to be a constant");
17567-
Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
17568-
}
17569-
return Arg;
17570-
}
17571-
1757217591
Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1757317592
const CallExpr *E) {
1757417593
llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
@@ -17619,15 +17638,8 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1761917638
case AMDGPU::BI__builtin_amdgcn_mov_dpp:
1762017639
case AMDGPU::BI__builtin_amdgcn_update_dpp: {
1762117640
llvm::SmallVector<llvm::Value *, 6> Args;
17622-
// Find out if any arguments are required to be integer constant
17623-
// expressions.
17624-
unsigned ICEArguments = 0;
17625-
ASTContext::GetBuiltinTypeError Error;
17626-
getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
17627-
assert(Error == ASTContext::GE_None && "Should not codegen an error");
17628-
for (unsigned I = 0; I != E->getNumArgs(); ++I) {
17629-
Args.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, I, E));
17630-
}
17641+
for (unsigned I = 0; I != E->getNumArgs(); ++I)
17642+
Args.push_back(EmitScalarExpr(E->getArg(I)));
1763117643
assert(Args.size() == 5 || Args.size() == 6);
1763217644
if (Args.size() == 5)
1763317645
Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
@@ -20603,7 +20615,17 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2060320615
Ops.push_back(AggValue);
2060420616
continue;
2060520617
}
20606-
Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
20618+
20619+
// If this is a normal argument, just emit it as a scalar.
20620+
if ((ICEArguments & (1 << i)) == 0) {
20621+
Ops.push_back(EmitScalarExpr(E->getArg(i)));
20622+
continue;
20623+
}
20624+
20625+
// If this is required to be a constant, constant fold it so that we know
20626+
// that the generated intrinsic gets a ConstantInt.
20627+
Ops.push_back(llvm::ConstantInt::get(
20628+
getLLVMContext(), *E->getArg(i)->getIntegerConstantExpr(getContext())));
2060720629
}
2060820630

2060920631
Intrinsic::ID ID = Intrinsic::not_intrinsic;

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4327,8 +4327,6 @@ class CodeGenFunction : public CodeGenTypeCache {
43274327
llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
43284328
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
43294329
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4330-
llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
4331-
const CallExpr *E);
43324330
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
43334331
llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
43344332
llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,

clang/test/CodeGenHIP/dpp-const-fold.hip

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)