Skip to content

Commit 69f1442

Browse files
authored
[LLVM] BasicTTIImpl allow unknown type during legality checking (#89848)
Make BasicTTIImplBase's `isTypeLegal` check handle unknown types. Current behavior is aborting. Motivated by a use case in SimplifyCFG, where `isTypeLegal` is called on a struct type and dies, when it could be treated as illegal and skipped. In general it could make sense for unknown types to be allowed, and by default just considered not legal, but the behavior can of course be overriden.
1 parent 054f7c0 commit 69f1442

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
426426
bool useAA() const { return getST()->useAA(); }
427427

428428
bool isTypeLegal(Type *Ty) {
429-
EVT VT = getTLI()->getValueType(DL, Ty);
429+
EVT VT = getTLI()->getValueType(DL, Ty, /*AllowUnknown=*/true);
430430
return getTLI()->isTypeLegal(VT);
431431
}
432432

llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,3 +2068,37 @@ cond.end: ; preds = %entry, %cond.false
20682068
%conv = sext i3 %cond to i8
20692069
ret i8 %conv
20702070
}
2071+
2072+
; Don't create a table with an unknown type
2073+
define { i8, i8 } @test_unknown_result_type(i8 %n) {
2074+
; CHECK-LABEL: @test_unknown_result_type(
2075+
; CHECK-NEXT: entry:
2076+
; CHECK-NEXT: switch i8 [[N:%.*]], label [[SW_DEFAULT:%.*]] [
2077+
; CHECK-NEXT: i8 0, label [[RETURN:%.*]]
2078+
; CHECK-NEXT: i8 1, label [[RETURN]]
2079+
; CHECK-NEXT: i8 2, label [[RETURN]]
2080+
; CHECK-NEXT: ]
2081+
; CHECK: sw.default:
2082+
; CHECK-NEXT: [[TMP0:%.*]] = insertvalue { i8, i8 } undef, i8 0, 0
2083+
; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { i8, i8 } [[TMP0]], i8 1, 1
2084+
; CHECK-NEXT: br label [[RETURN]]
2085+
; CHECK: return:
2086+
; CHECK-NEXT: [[RETVAL_0:%.*]] = phi { i8, i8 } [ undef, [[ENTRY:%.*]] ], [ undef, [[ENTRY]] ], [ undef, [[ENTRY]] ], [ [[TMP1]], [[SW_DEFAULT]] ]
2087+
; CHECK-NEXT: ret { i8, i8 } [[RETVAL_0]]
2088+
;
2089+
entry:
2090+
switch i8 %n, label %sw.default [
2091+
i8 0, label %return
2092+
i8 1, label %return
2093+
i8 2, label %return
2094+
]
2095+
2096+
sw.default: ; preds = %entry
2097+
%0 = insertvalue { i8, i8 } undef, i8 0, 0
2098+
%1 = insertvalue { i8, i8 } %0, i8 1, 1
2099+
br label %return
2100+
2101+
return: ; preds = %sw.default, %entry, %entry, %entry
2102+
%retval.0 = phi { i8, i8 } [ undef, %entry ], [ undef, %entry ], [ undef, %entry ], [ %1, %sw.default ]
2103+
ret { i8, i8 } %retval.0
2104+
}

0 commit comments

Comments
 (0)