[PATCH] D63226: AMDGPU: Fold readlane intrinsics of constants
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 12:49:54 PDT 2019
arsenm created this revision.
arsenm added reviewers: rampitec, nhaehnle.
Herald added subscribers: t-tye, tpr, dstuttard, yaxunl, wdng, jvesely, kzhuravl.
I'm not 100% sure about this, since I'm worried about IR transforms
that might end up introducing divergence downstream once replaced with
a constant, but I haven't come up with an example yet.
https://reviews.llvm.org/D63226
Files:
lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
Index: test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
===================================================================
--- test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -2433,6 +2433,62 @@
ret void
}
+; --------------------------------------------------------------------
+; llvm.amdgcn.readfirstlane
+; --------------------------------------------------------------------
+
+declare i32 @llvm.amdgcn.readfirstlane(i32)
+
+ at gv = constant i32 0
+
+define amdgpu_kernel void @readfirstlane_constant(i32 %arg) {
+; CHECK-LABEL: @readfirstlane_constant(
+; CHECK-NEXT: %var = call i32 @llvm.amdgcn.readfirstlane(i32 %arg)
+; CHECK-NEXT: store volatile i32 %var, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 0, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 123, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 ptrtoint (i32* @gv to i32), i32* undef, align 4
+; CHECK-NEXT: store volatile i32 undef, i32* undef, align 4
+ %var = call i32 @llvm.amdgcn.readfirstlane(i32 %arg)
+ %zero = call i32 @llvm.amdgcn.readfirstlane(i32 0)
+ %imm = call i32 @llvm.amdgcn.readfirstlane(i32 123)
+ %constexpr = call i32 @llvm.amdgcn.readfirstlane(i32 ptrtoint (i32* @gv to i32))
+ %undef = call i32 @llvm.amdgcn.readfirstlane(i32 undef)
+ store volatile i32 %var, i32* undef
+ store volatile i32 %zero, i32* undef
+ store volatile i32 %imm, i32* undef
+ store volatile i32 %constexpr, i32* undef
+ store volatile i32 %undef, i32* undef
+ ret void
+}
+
+; --------------------------------------------------------------------
+; llvm.amdgcn.readlane
+; --------------------------------------------------------------------
+
+declare i32 @llvm.amdgcn.readlane(i32, i32)
+
+define amdgpu_kernel void @readlane_constant(i32 %arg, i32 %lane) {
+; CHECK-LABEL: @readlane_constant(
+; CHECK-NEXT: %var = call i32 @llvm.amdgcn.readlane(i32 %arg, i32 7)
+; CHECK-NEXT: store volatile i32 %var, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 0, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 123, i32* undef, align 4
+; CHECK-NEXT: store volatile i32 ptrtoint (i32* @gv to i32), i32* undef, align 4
+; CHECK-NEXT: store volatile i32 undef, i32* undef, align 4
+ %var = call i32 @llvm.amdgcn.readlane(i32 %arg, i32 7)
+ %zero = call i32 @llvm.amdgcn.readlane(i32 0, i32 %lane)
+ %imm = call i32 @llvm.amdgcn.readlane(i32 123, i32 %lane)
+ %constexpr = call i32 @llvm.amdgcn.readlane(i32 ptrtoint (i32* @gv to i32), i32 %lane)
+ %undef = call i32 @llvm.amdgcn.readlane(i32 undef, i32 %lane)
+ store volatile i32 %var, i32* undef
+ store volatile i32 %zero, i32* undef
+ store volatile i32 %imm, i32* undef
+ store volatile i32 %constexpr, i32* undef
+ store volatile i32 %undef, i32* undef
+ ret void
+}
+
; --------------------------------------------------------------------
; llvm.amdgcn.update.dpp.i32
; --------------------------------------------------------------------
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3774,6 +3774,13 @@
II->setOperand(0, UndefValue::get(Old->getType()));
return II;
}
+ case Intrinsic::amdgcn_readfirstlane:
+ case Intrinsic::amdgcn_readlane: {
+ // A constant value is trivially uniform.
+ if (Constant *C = dyn_cast<Constant>(II->getArgOperand(0)))
+ return replaceInstUsesWith(*II, C);
+ break;
+ }
case Intrinsic::stackrestore: {
// If the save is right next to the restore, remove the restore. This can
// happen when variable allocas are DCE'd.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63226.204344.patch
Type: text/x-patch
Size: 3739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/1caa629f/attachment.bin>
More information about the llvm-commits
mailing list