[llvm] [SimplifyCFG] Delete the unnecessary range check for small mask operation (PR #65835)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 04:33:57 PDT 2023
================
@@ -0,0 +1,57 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=simplifycfg --switch-to-lookup -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; https://alive2.llvm.org/ce/z/tuxLhJ
+define i1 @switch_lookup_with_small_mask(i64 %x) {
+; CHECK-LABEL: @switch_lookup_with_small_mask(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[AND:%.*]] = and i64 [[X:%.*]], 15
+; CHECK-NEXT: [[SWITCH_CAST:%.*]] = trunc i64 [[AND]] to i16
+; CHECK-NEXT: [[SWITCH_SHIFTAMT:%.*]] = mul nuw nsw i16 [[SWITCH_CAST]], 1
+; CHECK-NEXT: [[SWITCH_DOWNSHIFT:%.*]] = lshr i16 1030, [[SWITCH_SHIFTAMT]]
+; CHECK-NEXT: [[SWITCH_MASKED:%.*]] = trunc i16 [[SWITCH_DOWNSHIFT]] to i1
+; CHECK-NEXT: ret i1 [[SWITCH_MASKED]]
+;
+entry:
+ %and = and i64 %x, 15
+ switch i64 %and, label %default [
+ i64 10, label %lor.end
+ i64 1, label %lor.end
+ i64 2, label %lor.end
+ ]
+
+default: ; preds = %entry
+ br label %lor.end
+
+lor.end: ; preds = %entry, %entry, %entry, %default
+ %0 = phi i1 [ true, %entry ], [ false, %default ], [ true, %entry ], [ true, %entry ]
+ ret i1 %0
+}
+
+define i1 @switch_lookup_with_small_urem(i64 %x) {
----------------
zmodem wrote:
This isn't much different from the previous test case. Maybe we could skip it?
https://github.com/llvm/llvm-project/pull/65835
More information about the llvm-commits
mailing list