[llvm] [DirectX] Add lowering support for `llvm.fsh[l|r].*` (PR #170570)

Sarah Spall via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 09:32:17 PST 2025


================
@@ -656,6 +659,32 @@ static Value *expandAtan2Intrinsic(CallInst *Orig) {
   return Result;
 }
 
+template <bool LeftFunnel>
+static Value *expandFunnelShiftIntrinsic(CallInst *Orig) {
+  Type *Ty = Orig->getType();
+  Value *A = Orig->getOperand(0);
+  Value *B = Orig->getOperand(1);
+  Value *Shift = Orig->getOperand(2);
+
+  IRBuilder<> Builder(Orig);
+
+  unsigned BitWidth = Ty->getScalarSizeInBits();
+  Constant *Mask = ConstantInt::get(Ty, BitWidth - 1);
+  Constant *Size = ConstantInt::get(Ty, BitWidth);
+
+  // The shift is not required to be masked as DXIL op will do so automatically
+  Value *Left =
+      LeftFunnel ? Builder.CreateShl(A, Shift) : Builder.CreateLShr(B, Shift);
----------------
spall wrote:

yeah that seems safer (and no more expensive) than assuming the dxil op does so.

https://github.com/llvm/llvm-project/pull/170570


More information about the llvm-commits mailing list