ソースを参照

Don't generate cond branch for scalar ternary conditional operator. (#2239)

Xiang Li 6 年 前
コミット
c41ab4fe6c

+ 2 - 1
tools/clang/lib/CodeGen/CGExprScalar.cpp

@@ -3701,7 +3701,8 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
     return tmp5;
   }
   // HLSL Change Starts
-  if (CGF.getLangOpts().HLSL && hlsl::IsHLSLVecType(E->getType())) {
+  if (CGF.getLangOpts().HLSL &&
+      (hlsl::IsHLSLVecType(E->getType()) || E->getType()->isArithmeticType())) {
     llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
     llvm::Value *LHS = Visit(lhsExpr);
     llvm::Value *RHS = Visit(rhsExpr);

+ 18 - 0
tools/clang/test/CodeGenHLSL/batch/expressions/operators/ternary_conditional_to_select.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -E main -T ps_6_2 %s | FileCheck %s
+
+// Make sure no branch.
+// CHECK-NOT:br i1
+
+float4 c;
+float x;
+float y;
+float z;
+
+
+float main() : SV_Target {
+
+float  v = c.y> 0.00001 ?
+    (c.y >= 0.2 ? (x+2) : y) : z;
+
+return v;
+}