Skip to content

Commit 6374c41

Browse files
committed
respond to pr comments
1 parent 34d9537 commit 6374c41

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6803,7 +6803,7 @@ void CodeGenFunction::FlattenAccessAndTypeLValue(
68036803
for (int64_t I = Size - 1; I > -1; I--) {
68046804
llvm::SmallVector<llvm::Value *, 4> IdxListCopy = IdxList;
68056805
IdxListCopy.push_back(llvm::ConstantInt::get(IdxTy, I));
6806-
WorkList.push_back({LVal, CAT->getElementType(), IdxListCopy});
6806+
WorkList.emplace_back(LVal, CAT->getElementType(), IdxListCopy);
68076807
}
68086808
} else if (const auto *RT = dyn_cast<RecordType>(T)) {
68096809
const RecordDecl *Record = RT->getOriginalDecl()->getDefinitionOrSelf();
@@ -6826,8 +6826,7 @@ void CodeGenFunction::FlattenAccessAndTypeLValue(
68266826
llvm::SmallVector<llvm::Value *, 4> IdxListCopy = IdxList;
68276827
IdxListCopy.push_back(llvm::ConstantInt::get(
68286828
IdxTy, 0)); // base struct should be at index zero
6829-
ReverseList.insert(ReverseList.end(),
6830-
{LVal, Base->getType(), IdxListCopy});
6829+
ReverseList.emplace_back(LVal, Base->getType(), IdxListCopy);
68316830
}
68326831
}
68336832

@@ -6848,13 +6847,12 @@ void CodeGenFunction::FlattenAccessAndTypeLValue(
68486847
RLValue = MakeAddrLValue(GEP, T);
68496848
}
68506849
LValue FieldLVal = EmitLValueForField(RLValue, FD, true);
6851-
ReverseList.insert(ReverseList.end(), {FieldLVal, FD->getType(), {}});
6850+
ReverseList.push_back({FieldLVal, FD->getType(), {}});
68526851
} else {
68536852
llvm::SmallVector<llvm::Value *, 4> IdxListCopy = IdxList;
68546853
IdxListCopy.push_back(
68556854
llvm::ConstantInt::get(IdxTy, Layout.getLLVMFieldNo(FD)));
6856-
ReverseList.insert(ReverseList.end(),
6857-
{LVal, FD->getType(), IdxListCopy});
6855+
ReverseList.emplace_back(LVal, FD->getType(), IdxListCopy);
68586856
}
68596857
}
68606858

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,8 @@ static Value *EmitHLSLElementwiseCast(CodeGenFunction &CGF, LValue SrcVal,
24002400
// if its a vector create a temp alloca to store into and return that
24012401
if (auto *VecTy = DestTy->getAs<VectorType>()) {
24022402
assert(LoadList.size() >= VecTy->getNumElements() &&
2403-
"Flattened type on RHS must have more elements than vector on LHS.");
2403+
"Flattened type on RHS must have the same number or more elements "
2404+
"than vector on LHS.");
24042405
llvm::Value *V =
24052406
CGF.Builder.CreateLoad(CGF.CreateIRTemp(DestTy, "flatcast.tmp"));
24062407
// write to V.

clang/test/CodeGenHLSL/BasicFeatures/AggregateSplatCast.hlsl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ struct S {
5454

5555
// struct splats
5656
// CHECK-LABEL: define void {{.*}}call3
57-
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4
57+
// CHECK: [[AA:%.*]] = alloca i32, align 4
5858
// CHECK: [[s:%.*]] = alloca %struct.S, align 1
59-
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4
60-
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4
61-
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0
59+
// CHECK-NEXT: store i32 %A, ptr [[AA]], align 4
60+
// CHECK-NEXT: [[L:%.*]] = load i32, ptr [[AA]], align 4
6261
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 0
6362
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 1
64-
// CHECK-NEXT: store i32 [[VL]], ptr [[G1]], align 4
65-
// CHECK-NEXT: [[C:%.*]] = sitofp i32 [[VL]] to float
63+
// CHECK-NEXT: store i32 [[L]], ptr [[G1]], align 4
64+
// CHECK-NEXT: [[C:%.*]] = sitofp i32 [[L]] to float
6665
// CHECK-NEXT: store float [[C]], ptr [[G2]], align 4
67-
export void call3() {
68-
int1 A = {1};
66+
export void call3(int A) {
6967
S s = (S)A;
7068
}
7169

@@ -87,7 +85,7 @@ export void call5() {
8785
}
8886

8987
struct BFields {
90-
double D;
88+
double DF;
9189
int E: 15;
9290
int : 8;
9391
float F;
@@ -110,9 +108,9 @@ struct Derived : BFields {
110108
// CHECK-NEXT: [[Gep3:%.*]] = getelementptr inbounds %struct.Derived, ptr [[D]], i32 0, i32 1
111109
// CHECK-NEXT: [[C:%.*]] = sitofp i32 [[B]] to double
112110
// CHECK-NEXT: store double [[C]], ptr [[Gep1]], align 8
113-
// CHECK-NEXT: [[D:%.*]] = trunc i32 [[B]] to i24
111+
// CHECK-NEXT: [[H:%.*]] = trunc i32 [[B]] to i24
114112
// CHECK-NEXT: [[BFL:%.*]] = load i24, ptr [[E]], align 1
115-
// CHECK-NEXT: [[BFV:%.*]] = and i24 [[D]], 32767
113+
// CHECK-NEXT: [[BFV:%.*]] = and i24 [[H]], 32767
116114
// CHECK-NEXT: [[BFC:%.*]] = and i24 [[BFL]], -32768
117115
// CHECK-NEXT: [[BFS:%.*]] = or i24 [[BFC]], [[BFV]]
118116
// CHECK-NEXT: store i24 [[BFS]], ptr [[E]], align 1

clang/test/CodeGenHLSL/BasicFeatures/StructElementwiseCast.hlsl

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
22

33
struct S {
44
int X;
@@ -245,3 +245,68 @@ export void call12() {
245245
int4 I = {1,2,3,4};
246246
Empty E = (Empty)I;
247247
}
248+
249+
struct MoreBFields {
250+
int A;
251+
uint64_t B: 60;
252+
float C;
253+
uint16_t D: 10;
254+
uint16_t E: 6;
255+
int : 32;
256+
double F;
257+
int : 8;
258+
uint G;
259+
};
260+
261+
// more complicated bitfield case
262+
// CHECK-LABEL: call13
263+
// CHECK: [[AA:%.*]] = alloca i32, align 4
264+
// CHECK-NEXT: [[MBF:%.*]] = alloca %struct.MoreBFields, align 1
265+
// CHECK-NEXT: store i32 %A, ptr [[AA]], align 4
266+
// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[AA]], align 4
267+
// get the gep for the struct.
268+
// CHECK-NEXT: [[Gep:%.*]] = getelementptr inbounds %struct.MoreBFields, ptr [[MBF]], i32 0
269+
// CHECK-NEXT: [[FieldB:%.*]] = getelementptr inbounds nuw %struct.MoreBFields, ptr [[Gep]], i32 0, i32 1
270+
// D and E share the same field index
271+
// CHECK-NEXT: [[FieldD:%.*]] = getelementptr inbounds nuw %struct.MoreBFields, ptr [[Gep]], i32 0, i32 3
272+
// CHECK-NEXT: [[FieldE:%.*]] = getelementptr inbounds nuw %struct.MoreBFields, ptr [[Gep]], i32 0, i32 3
273+
// CHECK-NEXT: [[FieldA:%.*]] = getelementptr inbounds %struct.MoreBFields, ptr [[MBF]], i32 0, i32 0
274+
// CHECK-NEXT: [[FieldC:%.*]] = getelementptr inbounds %struct.MoreBFields, ptr [[MBF]], i32 0, i32 2
275+
// CHECK-NEXT: [[FieldF:%.*]] = getelementptr inbounds %struct.MoreBFields, ptr [[MBF]], i32 0, i32 5
276+
// CHECK-NEXT: [[FieldG:%.*]] = getelementptr inbounds %struct.MoreBFields, ptr [[MBF]], i32 0, i32 7
277+
// store int A into field A
278+
// CHECK-NEXT: store i32 [[Z]], ptr [[FieldA]], align 4
279+
// store int A in bitField B, do necessary conversions
280+
// CHECK-NEXT: [[Conv:%.*]] = sext i32 [[Z]] to i64
281+
// CHECK-NEXT: [[BFL:%.*]] = load i64, ptr [[FieldB]], align 1
282+
// CHECK-NEXT: [[BFV:%.*]] = and i64 [[Conv]], 1152921504606846975
283+
// CHECK-NEXT: [[BFC:%.*]] = and i64 [[BFL]], -1152921504606846976
284+
// CHECK-NEXT: [[BFS:%.*]] = or i64 [[BFC]], [[BFV]]
285+
// CHECK-NEXT: store i64 [[BFS]], ptr [[FieldB]], align 1
286+
// store int A into field C
287+
// CHECK-NEXT: [[Conv5:%.*]] = sitofp i32 [[Z]] to float
288+
// CHECK-NEXT: store float [[Conv5]], ptr [[FieldC]], align 4
289+
// store int A into bitfield D
290+
// CHECK-NEXT: [[Conv6:%.*]] = trunc i32 [[Z]] to i16
291+
// CHECK-NEXT: [[FDL:%.*]] = load i16, ptr [[FieldD]], align 1
292+
// CHECK-NEXT: [[FDV:%.*]] = and i16 [[Conv6]], 1023
293+
// CHECK-NEXT: [[FDC:%.*]] = and i16 [[FDL]], -1024
294+
// CHECK-NEXT: [[FDS:%.*]] = or i16 [[FDC]], [[FDV]]
295+
// CHECK-NEXT: store i16 [[FDS]], ptr [[FieldD]], align 1
296+
// store int A into bitfield E;
297+
// CHECK-NEXT: [[Conv11:%.*]] = trunc i32 [[Z]] to i16
298+
// CHECK-NEXT: [[FEL:%.*]] = load i16, ptr [[FieldE]], align 1
299+
// CHECK-NEXT: [[FEV:%.*]] = and i16 [[Conv11]], 63
300+
// CHECK-NEXT: [[FESHL:%.*]] = shl i16 [[FEV]], 10
301+
// CHECK-NEXT: [[FEC:%.*]] = and i16 [[FEL]], 1023
302+
// CHECK-NEXT: [[FES:%.*]] = or i16 [[FEC]], [[FESHL]]
303+
// CHECK-NEXT: store i16 [[FES]], ptr [[FieldE]], align 1
304+
// store int A into field F
305+
// CHECK-NEXT: [[Conv16:%.*]] = sitofp i32 [[Z]] to double
306+
// CHECK-NEXT: store double [[Conv16]], ptr [[FieldF]], align 8
307+
// store int A into field G
308+
// CHECK-NEXT: store i32 [[Z]], ptr [[FieldG]], align 4
309+
// CHECK-NEXT: ret void
310+
export void call13(int A) {
311+
MoreBFields MBF = (MoreBFields)A;
312+
}

0 commit comments

Comments
 (0)