This is an archive of the discontinued LLVM Phabricator instance.

Mark threadIdx.x and friends as noundef.
ClosedPublic

Authored by jlebar on Apr 4 2023, 11:39 PM.

Details

Summary

threadIdx.x and similar functions never return undef.

Simple enough to say, but why does it matter?

Consider the following IR that reads threadIdx.x and blockIdx.x.

%a = call i32 @llvm.nvvm.read.ptx.sreg.ctaid.x(), !range !138
%b = call i32 @llvm.nvvm.read.ptx.sreg.tid.x(), !range !139
%c = shl nuw nsw i32 %a, 6
%linear_index = or i32 %c, %b
%linear_index.fr = freeze i32 %linear_index

If %a or %b may be undef, then computeKnownBits will not recurse through
the freeze instruction. Therefore we will not know anything about the
known bits of linear_index.fr, even though we have range metadata! Bad
Things fall out of this.

Diff Detail

Event Timeline

jlebar created this revision.Apr 4 2023, 11:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 11:39 PM
jlebar requested review of this revision.Apr 4 2023, 11:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 11:39 PM
tra accepted this revision.Apr 5 2023, 10:06 AM
This revision is now accepted and ready to land.Apr 5 2023, 10:06 AM
This revision was landed with ongoing or failed builds.Apr 5 2023, 1:44 PM
This revision was automatically updated to reflect the committed changes.