瀏覽代碼

Use lshr for uint vectors and remove the and for shift. (#1174)

Xiang Li 7 年之前
父節點
當前提交
9476863370

+ 6 - 0
tools/clang/lib/CodeGen/CGExprScalar.cpp

@@ -3075,6 +3075,12 @@ Value *ScalarExprEmitter::EmitShr(const BinOpInfo &Ops) {
 
   if (Ops.Ty->hasUnsignedIntegerRepresentation())
     return Builder.CreateLShr(Ops.LHS, RHS, "shr");
+  // HLSL Change Begin - check unsigned for vector.
+  if (hlsl::IsHLSLVecType(Ops.Ty)) {
+    if (hlsl::GetHLSLVecElementType(Ops.Ty)->hasUnsignedIntegerRepresentation())
+      return Builder.CreateLShr(Ops.LHS, RHS, "shr");
+  }
+  // HLSL Change End.
   return Builder.CreateAShr(Ops.LHS, RHS, "shr");
 }
 

+ 0 - 5
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -3873,11 +3873,6 @@ static void SimpleTransformForHLDXIR(Instruction *I,
       if (iOp2 != clampedOp2) {
         BO->setOperand(1, ConstantInt::get(op2->getType(), clampedOp2));
       }
-    } else {
-      Value *mask = ConstantInt::get(op2->getType(), bitWidth - 1);
-      IRBuilder<> Builder(I);
-      op2 = Builder.CreateAnd(op2, mask);
-      BO->setOperand(1, op2);
     }
   } break;
   }

+ 12 - 0
tools/clang/test/CodeGenHLSL/quick-test/vec_uint_shr.hlsl

@@ -0,0 +1,12 @@
+// RUN: %dxc -T ps_6_1 -E main %s | FileCheck %s
+
+// Make sure use lshr for uint vector.
+// CHECK: lshr
+// CHECK-NOT: ashr
+// Make sure no and for src1 of lshr.
+// CHECK-NOT: and
+
+
+float main(uint2 a:A, uint b:B) : SV_Target {
+  return (a>>b).y;
+}

+ 0 - 8
tools/clang/test/CodeGenHLSL/shift.hlsl

@@ -3,21 +3,13 @@
 // The shift for hlsl only use the LSB 5 bits (0-31 range) of src1 for int/uint.
 // CHECK: shl i32
 // CHECK: 18
-// CHECK: and i32
-// CHECK: 31
 // CHECK: ashr
-// CHECK: and i32
-// CHECK: 31
 // CHECK: lshr
 
 // The shift for hlsl only use the LSB 6 bits (0-63 range) of src1 for int64_t/uint64_t.
 // CHECK: shl i64
 // CHECK: 4
-// CHECK: and i64
-// CHECK: 63
 // CHECK: lshr
-// CHECK: and i64
-// CHECK: 63
 // CHECK: ashr
 
 uint64_t u;