From 4042038d00e80bbc94f63b21a976c341ba080aaa Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Tue, 12 Nov 2024 18:10:14 -0800 Subject: [PATCH] [GlobalISel] Move DemandedElt's APInt size assert after isValid() check This prevents the assertion from wrongly triggering on invalid LLT's --- llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp index fefa8f2ea8594..6ae6d56f2ca51 100644 --- a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp +++ b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp @@ -147,6 +147,15 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known, unsigned Opcode = MI.getOpcode(); LLT DstTy = MRI.getType(R); + // Handle the case where this is called on a register that does not have a + // type constraint (i.e. it has a register class constraint instead). This is + // unlikely to occur except by looking through copies but it is possible for + // the initial register being queried to be in this state. + if (!DstTy.isValid()) { + Known = KnownBits(); + return; + } + #ifndef NDEBUG if (DstTy.isFixedVector()) { assert( @@ -158,15 +167,6 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known, } #endif - // Handle the case where this is called on a register that does not have a - // type constraint (i.e. it has a register class constraint instead). This is - // unlikely to occur except by looking through copies but it is possible for - // the initial register being queried to be in this state. - if (!DstTy.isValid()) { - Known = KnownBits(); - return; - } - unsigned BitWidth = DstTy.getScalarSizeInBits(); auto CacheEntry = ComputeKnownBitsCache.find(R); if (CacheEntry != ComputeKnownBitsCache.end()) {