Prechádzať zdrojové kódy

Bring back clamp op2 to 0 ~ bitWidth-1 for shift. (#1199)

Xiang Li 7 rokov pred
rodič
commit
66e3606921

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

@@ -3873,6 +3873,11 @@ 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;
   }

+ 6 - 4
tools/clang/test/CodeGenHLSL/shift.hlsl

@@ -1,15 +1,17 @@
 // RUN: %dxc -E main -T ps_6_0  -not_use_legacy_cbuf_load %s | FileCheck %s
 
 // The shift for hlsl only use the LSB 5 bits (0-31 range) of src1 for int/uint.
-// CHECK: shl i32
-// CHECK: 18
+// CHECK: shl i32 {{.*}}, 18
+// CHECK: and i32 {{.*}}, 31
 // CHECK: ashr
+// CHECK: and i32 {{.*}}, 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: shl i64 {{.*}}, 4
+// CHECK: and i64 {{.*}}, 63
 // CHECK: lshr
+// CHECK: and i64 {{.*}}, 63
 // CHECK: ashr
 
 uint64_t u;