[llvm] [AMDGPU] Read EXEC at wave-size width in icmp/fcmp instcombine fold (PR #201358)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 06:47:59 PDT 2026


================
@@ -1644,15 +1644,19 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
         // intrinsic exposes) is one bit per thread, masked with the EXEC
         // register (which contains the bitmask of live threads). So a
         // comparison that always returns true is the same as a read of the
-        // EXEC register.
-        Metadata *MDArgs[] = {MDString::get(II.getContext(), "exec")};
+        // EXEC register. EXEC is wave-size bits wide, so read it at that width
+        // and zext/trunc to the return type.
+        Type *ExecTy = IC.Builder.getIntNTy(ST->getWavefrontSize());
+        StringRef ExecName = ST->isWave32() ? "exec_lo" : "exec";
+        Metadata *MDArgs[] = {MDString::get(II.getContext(), ExecName)};
         MDNode *MD = MDNode::get(II.getContext(), MDArgs);
         Value *Args[] = {MetadataAsValue::get(II.getContext(), MD)};
-        CallInst *NewCall = IC.Builder.CreateIntrinsic(Intrinsic::read_register,
-                                                       II.getType(), Args);
+        CallInst *NewCall =
+            IC.Builder.CreateIntrinsic(Intrinsic::read_register, ExecTy, Args);
----------------
arsenm wrote:

Why do we still have this combine? We switched to preferring ballot(true) vs. read_register for getting exec a long time ago. Also, we should really remove the icmp/fcmp intrinsics 

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


More information about the llvm-commits mailing list