-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[NVPTX][AutoUpgrade] Use integer min/max intrinsics instead of icmp, select #173097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexMaclean
wants to merge
1
commit into
llvm:main
Choose a base branch
from
AlexMaclean:dev/amaclean/auto-upgrade-min-max
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[NVPTX][AutoUpgrade] Use integer min/max intrinsics instead of icmp, select #173097
AlexMaclean
wants to merge
1
commit into
llvm:main
from
AlexMaclean:dev/amaclean/auto-upgrade-min-max
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-backend-nvptx @llvm/pr-subscribers-llvm-ir Author: Alex MacLean (AlexMaclean) ChangesFull diff: https://github.com/llvm/llvm-project/pull/173097.diff 2 Files Affected:
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 60505ac208c2c..9e4c5873e4ff8 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1538,6 +1538,19 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
{F->getReturnType()});
return true;
}
+ } else if (F->arg_size() == 2) {
+ Intrinsic::ID IID =
+ StringSwitch<Intrinsic::ID>(Name)
+ .Cases({"max.s", "max.i", "max.ll"}, Intrinsic::smax)
+ .Cases({"min.s", "min.i", "min.ll"}, Intrinsic::smin)
+ .Cases({"max.us", "max.ui", "max.ull"}, Intrinsic::umax)
+ .Cases({"min.us", "min.ui", "min.ull"}, Intrinsic::umin)
+ .Default(Intrinsic::not_intrinsic);
+ if (IID != Intrinsic::not_intrinsic) {
+ NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID,
+ {F->getReturnType()});
+ return true;
+ }
}
// Check for nvvm intrinsics that need a return type adjustment.
@@ -1581,10 +1594,6 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
// nvvm.ex2.approx.{f,ftz.f,d,f16x2}
Expand =
Name == "f" || Name == "ftz.f" || Name == "d" || Name == "f16x2";
- else if (Name.consume_front("max.") || Name.consume_front("min."))
- // nvvm.{min,max}.{i,ii,ui,ull}
- Expand = Name == "s" || Name == "i" || Name == "ll" || Name == "us" ||
- Name == "ui" || Name == "ull";
else if (Name.consume_front("atomic.load."))
// nvvm.atomic.load.add.{f32,f64}.p
// nvvm.atomic.load.{inc,dec}.32.p
@@ -2649,24 +2658,6 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
: AtomicRMWInst::UDecWrap;
Rep = Builder.CreateAtomicRMW(Op, Ptr, Val, MaybeAlign(),
AtomicOrdering::SequentiallyConsistent);
- } else if (Name.consume_front("max.") &&
- (Name == "s" || Name == "i" || Name == "ll" || Name == "us" ||
- Name == "ui" || Name == "ull")) {
- Value *Arg0 = CI->getArgOperand(0);
- Value *Arg1 = CI->getArgOperand(1);
- Value *Cmp = Name.starts_with("u")
- ? Builder.CreateICmpUGE(Arg0, Arg1, "max.cond")
- : Builder.CreateICmpSGE(Arg0, Arg1, "max.cond");
- Rep = Builder.CreateSelect(Cmp, Arg0, Arg1, "max");
- } else if (Name.consume_front("min.") &&
- (Name == "s" || Name == "i" || Name == "ll" || Name == "us" ||
- Name == "ui" || Name == "ull")) {
- Value *Arg0 = CI->getArgOperand(0);
- Value *Arg1 = CI->getArgOperand(1);
- Value *Cmp = Name.starts_with("u")
- ? Builder.CreateICmpULE(Arg0, Arg1, "min.cond")
- : Builder.CreateICmpSLE(Arg0, Arg1, "min.cond");
- Rep = Builder.CreateSelect(Cmp, Arg0, Arg1, "min");
} else if (Name == "clz.ll") {
// llvm.nvvm.clz.ll returns an i32, but llvm.ctlz.i64 returns an i64.
Value *Arg = CI->getArgOperand(0);
diff --git a/llvm/test/Assembler/auto_upgrade_nvvm_intrinsics.ll b/llvm/test/Assembler/auto_upgrade_nvvm_intrinsics.ll
index 0f749cf81f39b..4f07946e503c4 100644
--- a/llvm/test/Assembler/auto_upgrade_nvvm_intrinsics.ll
+++ b/llvm/test/Assembler/auto_upgrade_nvvm_intrinsics.ll
@@ -158,52 +158,40 @@ define void @tanh(float %a) {
; CHECK-LABEL: @min_max
define void @min_max(i16 %a1, i16 %a2, i32 %b1, i32 %b2, i64 %c1, i64 %c2) {
-; CHECK: [[maxs:%[a-zA-Z0-9.]+]] = icmp sge i16 %a1, %a2
-; CHECK: select i1 [[maxs]], i16 %a1, i16 %a2
+; CHECK: %r1 = call i16 @llvm.smax.i16(i16 %a1, i16 %a2)
%r1 = call i16 @llvm.nvvm.max.s(i16 %a1, i16 %a2)
-; CHECK: [[maxi:%[a-zA-Z0-9.]+]] = icmp sge i32 %b1, %b2
-; CHECK: select i1 [[maxi]], i32 %b1, i32 %b2
+; CHECK: %r2 = call i32 @llvm.smax.i32(i32 %b1, i32 %b2)
%r2 = call i32 @llvm.nvvm.max.i(i32 %b1, i32 %b2)
-; CHECK: [[maxll:%[a-zA-Z0-9.]+]] = icmp sge i64 %c1, %c2
-; CHECK: select i1 [[maxll]], i64 %c1, i64 %c2
+; CHECK: %r3 = call i64 @llvm.smax.i64(i64 %c1, i64 %c2)
%r3 = call i64 @llvm.nvvm.max.ll(i64 %c1, i64 %c2)
-; CHECK: [[maxus:%[a-zA-Z0-9.]+]] = icmp uge i16 %a1, %a2
-; CHECK: select i1 [[maxus]], i16 %a1, i16 %a2
+; CHECK: %r4 = call i16 @llvm.umax.i16(i16 %a1, i16 %a2)
%r4 = call i16 @llvm.nvvm.max.us(i16 %a1, i16 %a2)
-; CHECK: [[maxui:%[a-zA-Z0-9.]+]] = icmp uge i32 %b1, %b2
-; CHECK: select i1 [[maxui]], i32 %b1, i32 %b2
+; CHECK: %r5 = call i32 @llvm.umax.i32(i32 %b1, i32 %b2)
%r5 = call i32 @llvm.nvvm.max.ui(i32 %b1, i32 %b2)
-; CHECK: [[maxull:%[a-zA-Z0-9.]+]] = icmp uge i64 %c1, %c2
-; CHECK: select i1 [[maxull]], i64 %c1, i64 %c2
+; CHECK: %r6 = call i64 @llvm.umax.i64(i64 %c1, i64 %c2)
%r6 = call i64 @llvm.nvvm.max.ull(i64 %c1, i64 %c2)
-; CHECK: [[mins:%[a-zA-Z0-9.]+]] = icmp sle i16 %a1, %a2
-; CHECK: select i1 [[mins]], i16 %a1, i16 %a2
+; CHECK: %r7 = call i16 @llvm.smin.i16(i16 %a1, i16 %a2)
%r7 = call i16 @llvm.nvvm.min.s(i16 %a1, i16 %a2)
-; CHECK: [[mini:%[a-zA-Z0-9.]+]] = icmp sle i32 %b1, %b2
-; CHECK: select i1 [[mini]], i32 %b1, i32 %b2
+; CHECK: %r8 = call i32 @llvm.smin.i32(i32 %b1, i32 %b2)
%r8 = call i32 @llvm.nvvm.min.i(i32 %b1, i32 %b2)
-; CHECK: [[minll:%[a-zA-Z0-9.]+]] = icmp sle i64 %c1, %c2
-; CHECK: select i1 [[minll]], i64 %c1, i64 %c2
+; CHECK: %r9 = call i64 @llvm.smin.i64(i64 %c1, i64 %c2)
%r9 = call i64 @llvm.nvvm.min.ll(i64 %c1, i64 %c2)
-; CHECK: [[minus:%[a-zA-Z0-9.]+]] = icmp ule i16 %a1, %a2
-; CHECK: select i1 [[minus]], i16 %a1, i16 %a2
+; CHECK: %r10 = call i16 @llvm.umin.i16(i16 %a1, i16 %a2)
%r10 = call i16 @llvm.nvvm.min.us(i16 %a1, i16 %a2)
-; CHECK: [[minui:%[a-zA-Z0-9.]+]] = icmp ule i32 %b1, %b2
-; CHECK: select i1 [[minui]], i32 %b1, i32 %b2
+; CHECK: %r11 = call i32 @llvm.umin.i32(i32 %b1, i32 %b2)
%r11 = call i32 @llvm.nvvm.min.ui(i32 %b1, i32 %b2)
-; CHECK: [[minull:%[a-zA-Z0-9.]+]] = icmp ule i64 %c1, %c2
-; CHECK: select i1 [[minull]], i64 %c1, i64 %c2
+; CHECK: %r12 = call i64 @llvm.umin.i64(i64 %c1, i64 %c2)
%r12 = call i64 @llvm.nvvm.min.ull(i64 %c1, i64 %c2)
ret void
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.