diff --git a/llvm/lib/Transforms/Utils/PetarCountCttz.cpp b/llvm/lib/Transforms/Utils/PetarCountCttz.cpp index 33a7af390d32e..93ad2457cac3b 100644 --- a/llvm/lib/Transforms/Utils/PetarCountCttz.cpp +++ b/llvm/lib/Transforms/Utils/PetarCountCttz.cpp @@ -8,18 +8,18 @@ int countCttzIntrinsicAppearance=0; PreservedAnalyses PetarCountCttzPass::run(Function &F, FunctionAnalysisManager &AM) { errs() << "Function name: " << F.getName() << "\n"; - errs() << "\n-------------------------------\n"; - errs() << "Instructions within this function!\n"; + //errs() << "\n-------------------------------\n"; + //errs() << "Instructions within this function!\n"; for(BasicBlock& BB: F){ for(Instruction& I: BB){ - errs()<< I.getName() << "\n"; + //errs()<< I.getName() << "\n"; IntrinsicInst *II = dyn_cast(&I); if(II && (II->getIntrinsicID() == Intrinsic::cttz)) countCttzIntrinsicAppearance++; } } - errs() << "\n-------------------------------\n"; + //errs() << "\n-------------------------------\n"; errs() << "Total number of cttz intrinsic appearances is equal to: " << countCttzIntrinsicAppearance << ".\n"; return PreservedAnalyses::all(); diff --git a/llvm/test/Transforms/Util/petar-count-cttz.ll b/llvm/test/Transforms/Util/petar-count-cttz.ll new file mode 100644 index 0000000000000..941cffca4587a --- /dev/null +++ b/llvm/test/Transforms/Util/petar-count-cttz.ll @@ -0,0 +1,48 @@ +; RUN: opt -disable-output -passes=petarcountcttz %s 2>&1 | FileCheck %s + +; CHECK: Function name: cttz_64_eq_select +; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 1. +declare i64 @llvm.cttz.i64(i64, i1) +define i64 @cttz_64_eq_select(i64 %v) nounwind { + + %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true) + %tobool = icmp eq i64 %v, 0 + %.op = add nuw nsw i64 %cnt, 6 + %add = select i1 %tobool, i64 5, i64 %.op + ret i64 %add +} + +; CHECK-NEXT: Function name: cttz_64_ne_select +; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 2. +define i64 @cttz_64_ne_select(i64 %v) nounwind { + + %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true) + %tobool = icmp ne i64 %v, 0 + %.op = add nuw nsw i64 %cnt, 6 + %add = select i1 %tobool, i64 %.op, i64 5 + ret i64 %add +} + +; CHECK-NEXT: Function name: cttz_32_eq_select +; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 3. +declare i32 @llvm.cttz.i32(i32, i1) +define i32 @cttz_32_eq_select(i32 %v) nounwind { + + %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true) + %tobool = icmp eq i32 %v, 0 + %.op = add nuw nsw i32 %cnt, 6 + %add = select i1 %tobool, i32 5, i32 %.op + ret i32 %add +} + +; CHECK-NEXT: Function name: cttz_32_ne_select +; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 4. +define i32 @cttz_32_ne_select(i32 %v) nounwind { + + %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true) + %tobool = icmp ne i32 %v, 0 + %.op = add nuw nsw i32 %cnt, 6 + %add = select i1 %tobool, i32 %.op, i32 5 + ret i32 %add +} + diff --git a/petar_notes.txt b/petar_notes.txt new file mode 100644 index 0000000000000..e4afaf2f2e203 --- /dev/null +++ b/petar_notes.txt @@ -0,0 +1,6 @@ +LLVM project +Author: Chris Lattner +Master thesis title: Semantic detection of a CRC function for RISCV in LLVM + +What have I learned so far? +