[llvm] 7b099a4 - LowerTypeTests: Remove the optimization for llvm.cond.loop.

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 13 14:16:19 PST 2026


Author: Peter Collingbourne
Date: 2026-02-13T14:16:15-08:00
New Revision: 7b099a4c53178c249043f8c477511977b4ed5ca6

URL: https://github.com/llvm/llvm-project/commit/7b099a4c53178c249043f8c477511977b4ed5ca6
DIFF: https://github.com/llvm/llvm-project/commit/7b099a4c53178c249043f8c477511977b4ed5ca6.diff

LOG: LowerTypeTests: Remove the optimization for llvm.cond.loop.

Because in the new IR pattern for conditional traps the llvm.cond.loop
is generated late, the LowerTypeTests pass will never see it, so we no
longer need to be able to optimize it. Therefore, remove the code for
optimizing it.

This reverts commit 1de721c414407f4b92d3e2458ce9ca38563cef9c.

Reviewers: fmayer, vitalybuka

Reviewed By: fmayer

Pull Request: https://github.com/llvm/llvm-project/pull/181301

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Removed: 
    llvm/test/Transforms/LowerTypeTests/cond-loop.ll


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index c84bdaa1b0f86..ae24476e57706 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -782,11 +782,11 @@ Value *LowerTypeTestsModule::lowerTypeTestCall(Metadata *TypeId, CallInst *CI,
   if (TIL.TheKind == TypeTestResolution::AllOnes)
     return OffsetInRange;
 
-  if (CI->hasOneUse()) {
-    // See if the intrinsic is used in the following common pattern:
-    //   br(llvm.type.test(...), thenbb, elsebb)
-    // where nothing happens between the type test and the br.
-    // If so, create slightly simpler IR.
+  // See if the intrinsic is used in the following common pattern:
+  //   br(llvm.type.test(...), thenbb, elsebb)
+  // where nothing happens between the type test and the br.
+  // If so, create slightly simpler IR.
+  if (CI->hasOneUse())
     if (auto *Br = dyn_cast<BranchInst>(*CI->user_begin()))
       if (CI->getNextNode() == Br) {
         BasicBlock *Then = InitialBB->splitBasicBlock(CI->getIterator());
@@ -803,21 +803,6 @@ Value *LowerTypeTestsModule::lowerTypeTestCall(Metadata *TypeId, CallInst *CI,
         IRBuilder<> ThenB(CI);
         return createBitSetTest(ThenB, TIL, BitOffset);
       }
-    // Also look for the pattern llvm.cond.loop(not(llvm.type.test)) and
-    // generate a separate llvm.cond.loop for the first phase of the check if
-    // found.
-    if (auto *Xor = dyn_cast<BinaryOperator>(*CI->user_begin());
-        CI->getNextNode() == Xor && Xor->getOpcode() == BinaryOperator::Xor &&
-        Xor->getOperand(1) == ConstantInt::getTrue(M.getContext()) &&
-        Xor->hasOneUse()) {
-      if (auto *CondLoop = dyn_cast<IntrinsicInst>(*Xor->user_begin());
-          Xor->getNextNode() == CondLoop &&
-          CondLoop->getIntrinsicID() == Intrinsic::cond_loop) {
-        B.CreateIntrinsic(Intrinsic::cond_loop, B.CreateNot(OffsetInRange));
-        return createBitSetTest(B, TIL, BitOffset);
-      }
-    }
-  }
 
   MDBuilder MDB(M.getContext());
   IRBuilder<> ThenB(SplitBlockAndInsertIfThen(OffsetInRange, CI, false,

diff  --git a/llvm/test/Transforms/LowerTypeTests/cond-loop.ll b/llvm/test/Transforms/LowerTypeTests/cond-loop.ll
deleted file mode 100644
index 8049966f58b14..0000000000000
--- a/llvm/test/Transforms/LowerTypeTests/cond-loop.ll
+++ /dev/null
@@ -1,45 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
-; RUN: opt -S -passes=lowertypetests -lowertypetests-summary-action=import -lowertypetests-read-summary=%S/Inputs/import.yaml %s | FileCheck %s
-
-target datalayout = "e-p:64:64"
-target triple = "x86_64-unknown-linux"
-
-define void @allones7(ptr %p) {
-; CHECK-LABEL: define void @allones7(
-; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
-; CHECK-NEXT:    [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_allones7_global_addr to i64), [[TMP1]]
-; CHECK-NEXT:    [[TMP7:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 ptrtoint (ptr @__typeid_allones7_align to i64))
-; CHECK-NEXT:    [[TMP8:%.*]] = icmp ule i64 [[TMP7]], ptrtoint (ptr @__typeid_allones7_size_m1 to i64)
-; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[TMP8]], true
-; CHECK-NEXT:    call void @llvm.cond.loop(i1 [[NOT]])
-; CHECK-NEXT:    ret void
-;
-  %x = call i1 @llvm.type.test(ptr %p, metadata !"allones7")
-  %not = xor i1 %x, true
-  call void @llvm.cond.loop(i1 %not)
-  ret void
-}
-
-define void @bytearray7(ptr %p) {
-; CHECK-LABEL: define void @bytearray7(
-; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
-; CHECK-NEXT:    [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_bytearray7_global_addr to i64), [[TMP1]]
-; CHECK-NEXT:    [[TMP7:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 ptrtoint (ptr @__typeid_bytearray7_align to i64))
-; CHECK-NEXT:    [[TMP8:%.*]] = icmp ule i64 [[TMP7]], ptrtoint (ptr @__typeid_bytearray7_size_m1 to i64)
-; CHECK-NEXT:    [[TMP5:%.*]] = xor i1 [[TMP8]], true
-; CHECK-NEXT:    call void @llvm.cond.loop(i1 [[TMP5]])
-; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr i8, ptr @__typeid_bytearray7_byte_array, i64 [[TMP7]]
-; CHECK-NEXT:    [[TMP11:%.*]] = load i8, ptr [[TMP10]], align 1
-; CHECK-NEXT:    [[TMP12:%.*]] = and i8 [[TMP11]], ptrtoint (ptr @__typeid_bytearray7_bit_mask to i8)
-; CHECK-NEXT:    [[TMP13:%.*]] = icmp ne i8 [[TMP12]], 0
-; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[TMP13]], true
-; CHECK-NEXT:    call void @llvm.cond.loop(i1 [[NOT]])
-; CHECK-NEXT:    ret void
-;
-  %x = call i1 @llvm.type.test(ptr %p, metadata !"bytearray7")
-  %not = xor i1 %x, true
-  call void @llvm.cond.loop(i1 %not)
-  ret void
-}


        


More information about the llvm-commits mailing list