-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLVM] BasicTTIImpl allow unknown type during legality checking #89848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Billy Zhu (zyx-billy) ChangesMake BasicTTIImplBase's Motivated by a use case in SimplifyCFG, where Full diff: https://github.com/llvm/llvm-project/pull/89848.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 06a19c75cf873a..ad7edcf7f9d6a7 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -426,7 +426,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
bool useAA() const { return getST()->useAA(); }
bool isTypeLegal(Type *Ty) {
- EVT VT = getTLI()->getValueType(DL, Ty);
+ EVT VT = getTLI()->getValueType(DL, Ty, /*AllowUnknown=*/true);
return getTLI()->isTypeLegal(VT);
}
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
index 3873f0c0ae0bbd..9e3bb2368e7a4d 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
@@ -2068,3 +2068,25 @@ cond.end: ; preds = %entry, %cond.false
%conv = sext i3 %cond to i8
ret i8 %conv
}
+
+; Don't create a table with an unknown type
+define { i8, i8 } @test_unknown_result_type(i8 %n) {
+; CHECK-LABEL: @test_unknown_result_type(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: switch
+entry:
+ switch i8 %n, label %sw.default [
+ i8 0, label %return
+ i8 1, label %return
+ i8 2, label %return
+ ]
+
+sw.default: ; preds = %entry
+ %0 = insertvalue { i8, i8 } undef, i8 0, 0
+ %1 = insertvalue { i8, i8 } %0, i8 1, 1
+ br label %return
+
+return: ; preds = %sw.default, %entry, %entry, %entry
+ %retval.0 = phi { i8, i8 } [ undef, %entry ], [ undef, %entry ], [ undef, %entry ], [ %1, %sw.default ]
+ ret { i8, i8 } %retval.0
+}
|
LGTM but please get a review from someone else |
0e766c4
to
b9f0402
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. Please LMK if this is too lenient for other use cases (we can consider parameterizing it too).