[llvm] [SimplifyCFG] Replace unreachable switch lookup table holes with poison (PR #94990)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 03:48:05 PDT 2024


================
@@ -6281,8 +6282,15 @@ SwitchLookupTable::SwitchLookupTable(
     uint64_t Idx = (CaseVal->getValue() - Offset->getValue()).getLimitedValue();
     TableContents[Idx] = CaseRes;
 
-    if (CaseRes != SingleValue)
-      SingleValue = nullptr;
+    if (CaseRes != SingleValue) {
----------------
DaMatrix wrote:

Because we don't need to change `SingleValue` if `CaseRes` is equal. If this is replaced with a check for `!isa<UndefValue>(CaseRes)` then a lookup table with two identical values won't be able to be optimized into a constant, since it'd see that the second value isn't undef and would then set `SingleValue` to `nullptr`. I guess it would be possible to swap the conditions on this if and the inner `else if`, but I don't think that would help code readability at all.

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


More information about the llvm-commits mailing list