2
0
Эх сурвалжийг харах

[spirv] Handle literal float type in getValueOne() (#1040)

Ehsan 7 жил өмнө
parent
commit
d47339e142

+ 10 - 0
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -1911,6 +1911,14 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
       llvm::APFloat::getSizeInBits(astContext.getFloatTypeSemantics(toType)) ==
           32)
     hint.setHint(astContext.IntTy);
+  // 'literal float' to 'float' conversion where intended type is float32.
+  if (toType->isFloatingType() &&
+      subExprType->isSpecificBuiltinType(BuiltinType::LitFloat) &&
+      llvm::APFloat::getSizeInBits(astContext.getFloatTypeSemantics(toType)) ==
+          32)
+    hint.setHint(astContext.FloatTy);
+
+
   // TODO: We could provide other useful hints. For instance:
   // For the case of toType being a boolean, if the fromType is a literal float,
   // we could provide a FloatTy hint and if the fromType is a literal integer,
@@ -7410,6 +7418,8 @@ uint32_t SPIRVEmitter::getValueOne(QualType type) {
         return theBuilder.getConstantUint32(1);
       }
 
+      if (scalarType->isSpecificBuiltinType(BuiltinType::LitFloat))
+        scalarType = typeTranslator.getIntendedLiteralType(scalarType);
       if (const auto *builtinType = scalarType->getAs<BuiltinType>()) {
         // TODO: Add support for other types that are not covered yet.
         switch (builtinType->getKind()) {

+ 5 - 0
tools/clang/test/CodeGenSPIRV/intrinsics.rcp.hlsl

@@ -45,4 +45,9 @@ void main() {
 // CHECK-NEXT: [[rcpf1:%\d+]] = OpFDiv %v3double [[v3d1]] [[f1]]
 // CHECK-NEXT:       {{%\d+}} = OpCompositeConstruct %mat2v3double [[rcpf0]] [[rcpf1]]
   rcpf = rcp(f);
+
+// Case with literal float argument.
+// CHECK:      [[one_plus_two:%\d+]] = OpFAdd %float %float_1 %float_2
+// CHECK-NEXT:              {{%\d+}} = OpFDiv %float %float_1 [[one_plus_two]]
+  float g = rcp(1.0 + 2.0);
 }