[llvm] 1b44015 - Make switch-to-lookup-large-types.ll more reliable
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 6 05:35:52 PST 2023
Author: Alex Richardson
Date: 2023-01-06T13:35:43Z
New Revision: 1b440155c11c373c00c872abf41c47a01946a234
URL: https://github.com/llvm/llvm-project/commit/1b440155c11c373c00c872abf41c47a01946a234
DIFF: https://github.com/llvm/llvm-project/commit/1b440155c11c373c00c872abf41c47a01946a234.diff
LOG: Make switch-to-lookup-large-types.ll more reliable
When larger integer types are natively supported simplifycfg will use an
inline constant instead of a global variable for this transform. I noticed
this while trying to automatically infer the datalayout from the target
triple in opt if it is not explicitly specified. Since the x86_64
datalayout includes "n8:16:32:64", this test started failing.
While touching this file also change i128 to i64 in the first test since
this was intended behaviour in the original commit.
Reviewed By: spatel, fhahn
Differential Revision: https://reviews.llvm.org/D141055
Added:
Modified:
llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-large-types.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-large-types.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-large-types.ll
index 70725468a1114..80c855ee6bec6 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-large-types.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/switch-to-lookup-large-types.ll
@@ -1,29 +1,41 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --scrub-attributes --check-globals
-; RUN: opt -passes=simplifycfg --switch-to-lookup -S %s | FileCheck %s
+; RUN: opt '-passes=simplifycfg<switch-to-lookup>' -data-layout="e" -S %s | FileCheck %s
+;; If basic integer types are natively supported, the value is generated inline instead of using a global
+; RUN: opt '-passes=simplifycfg<switch-to-lookup>' -data-layout="e-n8:16:32:64" -S %s | FileCheck %s --check-prefix=INLINE
target triple = "x86_64-unknown-linux-gnu"
;.
; CHECK: @[[SWITCH_TABLE_SWITCH_TO_LOOKUP_I64:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [3 x i8] c"\03\01\02", align 1
; CHECK: @[[SWITCH_TABLE_SWITCH_TO_LOOKUP_I128:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [3 x i8] c"\03\01\02", align 1
;.
-define i8 @switch_to_lookup_i64(i128 %x){
+define i8 @switch_to_lookup_i64(i64 %x){
; CHECK-LABEL: @switch_to_lookup_i64(
; CHECK-NEXT: start:
-; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i128 [[X:%.*]], 3
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i64 [[X:%.*]], 3
; CHECK-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[COMMON_RET:%.*]]
; CHECK: common.ret:
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i8 [ [[SWITCH_LOAD:%.*]], [[SWITCH_LOOKUP]] ], [ 10, [[START:%.*]] ]
; CHECK-NEXT: ret i8 [[COMMON_RET_OP]]
; CHECK: switch.lookup:
-; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i8], ptr @switch.table.switch_to_lookup_i64, i32 0, i128 [[X]]
+; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i8], ptr @switch.table.switch_to_lookup_i64, i32 0, i64 [[X]]
; CHECK-NEXT: [[SWITCH_LOAD]] = load i8, ptr [[SWITCH_GEP]], align 1
; CHECK-NEXT: br label [[COMMON_RET]]
;
+; INLINE-LABEL: @switch_to_lookup_i64(
+; INLINE-NEXT: start:
+; INLINE-NEXT: [[TMP0:%.*]] = icmp ult i64 [[X:%.*]], 3
+; INLINE-NEXT: [[SWITCH_CAST:%.*]] = trunc i64 [[X]] to i24
+; INLINE-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul i24 [[SWITCH_CAST]], 8
+; INLINE-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i24 131331, [[SWITCH_SHIFTAMT]]
+; INLINE-NEXT: [[SWITCH_MASKED:%.*]] = trunc i24 [[SWITCH_DOWNSHIFT]] to i8
+; INLINE-NEXT: [[COMMON_RET_OP:%.*]] = select i1 [[TMP0]], i8 [[SWITCH_MASKED]], i8 10
+; INLINE-NEXT: ret i8 [[COMMON_RET_OP]]
+;
start:
- switch i128 %x, label %default [
- i128 0, label %end
- i128 1, label %bb1
- i128 2, label %bb2
+ switch i64 %x, label %default [
+ i64 0, label %end
+ i64 1, label %bb1
+ i64 2, label %bb2
]
bb1:
@@ -53,6 +65,16 @@ define i8 @switch_to_lookup_i128(i128 %x){
; CHECK-NEXT: [[SWITCH_LOAD]] = load i8, ptr [[SWITCH_GEP]], align 1
; CHECK-NEXT: br label [[COMMON_RET]]
;
+; INLINE-LABEL: @switch_to_lookup_i128(
+; INLINE-NEXT: start:
+; INLINE-NEXT: [[TMP0:%.*]] = icmp ult i128 [[X:%.*]], 3
+; INLINE-NEXT: [[SWITCH_CAST:%.*]] = trunc i128 [[X]] to i24
+; INLINE-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul i24 [[SWITCH_CAST]], 8
+; INLINE-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i24 131331, [[SWITCH_SHIFTAMT]]
+; INLINE-NEXT: [[SWITCH_MASKED:%.*]] = trunc i24 [[SWITCH_DOWNSHIFT]] to i8
+; INLINE-NEXT: [[COMMON_RET_OP:%.*]] = select i1 [[TMP0]], i8 [[SWITCH_MASKED]], i8 10
+; INLINE-NEXT: ret i8 [[COMMON_RET_OP]]
+;
start:
switch i128 %x, label %default [
i128 0, label %end
More information about the llvm-commits
mailing list