[llvm] [NVPTX] Improve folding to mad with immediate 1 (PR #93628)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 13:54:25 PDT 2024
================
@@ -0,0 +1,101 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 -O1 | FileCheck %s
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -O1 | FileCheck %s
+; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_20 -O1 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -O1 | %ptxas-verify %}
+
+define i32 @test1(i32 %n, i32 %m) {
+;
+; CHECK: ld.param.u32 %[[N:r[0-9]+]], [test1_param_0];
+; CHECK: ld.param.u32 %[[M:r[0-9]+]], [test1_param_1];
+; CHECK: mad.lo.s32 %[[MAD:r[0-9]+]], %[[M]], %[[N]], %[[M]];
+; CHECK: st.param.b32 [func_retval0+0], %[[MAD]];
+;
+ %add = add i32 %n, 1
+ %mul = mul i32 %add, %m
+ ret i32 %mul
+}
+
+define i32 @test1_rev(i32 %n, i32 %m) {
+;
+; CHECK: ld.param.u32 %[[N:r[0-9]+]], [test1_rev_param_0];
+; CHECK: ld.param.u32 %[[M:r[0-9]+]], [test1_rev_param_1];
+; CHECK: mad.lo.s32 %[[MAD:r[0-9]+]], %[[M]], %[[N]], %[[M]];
+; CHECK: st.param.b32 [func_retval0+0], %[[MAD]];
+;
+ %add = add i32 %n, 1
+ %mul = mul i32 %m, %add
+ ret i32 %mul
+}
+
+; Transpose (mul (select)) if it can then be folded to mad
----------------
Artem-B wrote:
This kind of optimization is not target-specific and should probably be done somewhere in instcombine. Perhaps move the optimization of `mul(m,select(1,n))` there as a separate patch?
https://github.com/llvm/llvm-project/pull/93628
More information about the llvm-commits
mailing list