@@ -2045,6 +2045,20 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II,
20452045 return BM->addBinaryInst (OpFAdd, Ty, Mul,
20462046 transValue (II->getArgOperand (2 ), BB), BB);
20472047 }
2048+ case Intrinsic::usub_sat: {
2049+ // usub.sat(a, b) -> (a > b) ? a - b : 0
2050+ SPIRVType *Ty = transType (II->getType ());
2051+ Type *BoolTy = IntegerType::getInt1Ty (M->getContext ());
2052+ SPIRVValue *FirstArgVal = transValue (II->getArgOperand (0 ), BB);
2053+ SPIRVValue *SecondArgVal = transValue (II->getArgOperand (1 ), BB);
2054+
2055+ SPIRVValue *Sub =
2056+ BM->addBinaryInst (OpISub, Ty, FirstArgVal, SecondArgVal, BB);
2057+ SPIRVValue *Cmp = BM->addCmpInst (OpUGreaterThan, transType (BoolTy),
2058+ FirstArgVal, SecondArgVal, BB);
2059+ SPIRVValue *Zero = transValue (Constant::getNullValue (II->getType ()), BB);
2060+ return BM->addSelectInst (Cmp, Sub, Zero, BB);
2061+ }
20482062 case Intrinsic::memset: {
20492063 // Generally there is no direct mapping of memset to SPIR-V. But it turns
20502064 // out that memset is emitted by Clang for initialization in default
0 commit comments