[clang] [CIR] Add support for the IdiomRecognizer pass (PR #208854)

Rithik Sharma via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 13 21:02:07 PDT 2026


================
@@ -1,2 +1,50 @@
 // RUN: %clang_cc1 -fclangir -emit-cir -mmlir --mlir-print-ir-after-all -clangir-enable-idiom-recognizer %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIR
 // CIR: IR Dump After IdiomRecognizer: cir-idiom-recognizer
+
+// The implicit-check-not on the RAISED run makes the original std::find call an
+// error anywhere in the post-pass dump, so the test only passes if that call was
+// raised to cir.std.find rather than left in place.
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -clangir-enable-idiom-recognizer -emit-cir -mmlir --mlir-print-ir-after=cir-idiom-recognizer %s -o %t.cir 2>&1 | FileCheck %s --check-prefix=RAISED '--implicit-check-not=cir.call @_ZSt4findIPccET_S1_S1_RKT0_'
+// RUN: FileCheck %s --check-prefix=FINAL --input-file=%t.cir
+
+namespace std {
+template <class Iter, class T>
+__attribute__((pure)) Iter find(Iter, Iter, const T &) noexcept;
+}
+
+char *test_find(char *first, char *last, const char &value) {
+  return std::find(first, last, value);
+}
+// Raised, then lowered back in operand order with its call attributes.
+// RAISED: cir.std.find(
+// RAISED-SAME: @_ZSt4find
+// FINAL: %[[FIRST:.*]] = cir.load{{.*}} : !cir.ptr<!cir.ptr<!s8i>>
----------------
SharmaRithik wrote:

Fixed, each negative now asserts no cir.std.find and its plain call surviving to the final output.

https://github.com/llvm/llvm-project/pull/208854


More information about the cfe-commits mailing list