[llvm] [DXIL] Implement pow lowering (PR #86733)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 15:12:09 PDT 2024


================
@@ -197,6 +198,26 @@ static bool expandLog10Intrinsic(CallInst *Orig) {
   return expandLogIntrinsic(Orig, numbers::ln2f / numbers::ln10f);
 }
 
+static bool expandPowIntrinsic(CallInst *Orig) {
+
+  Value *X = Orig->getOperand(0);
+  Value *Y = Orig->getOperand(1);
+  Type *Ty = X->getType();
+  IRBuilder<> Builder(Orig->getParent());
+  Builder.SetInsertPoint(Orig);
+
+  auto *Log2Call =
----------------
farzonl wrote:

Good question. So consider this implementation the base implementation without running any compiler optimizations. As such we can compare it to [DXC's TranslatePowImpl](https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/HLSL/HLOperationLower.cpp#L841C1-L846C78). So the first half of that is an fxc compat mode which I don't think we should carry forward. The second half of that is  exactly what we see in  https://godbolt.org/z/G5bKWz9j4 ie exp2(y*log2(x))

What you are refering to is something we could handle if
1.  we could determine X to be 0 at compile time
2.  if that[ constant could be propograted ](https://en.wikipedia.org/wiki/Constant_folding#Constant_propagation)
3. and then we could do CSE or a strength reduction  where we replace 0^3 -> 0

See example below DXC only returns 0 when both x and y in pow(x,y) are constants
https://godbolt.org/z/h595E7xP5

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


More information about the llvm-commits mailing list