From 92d02027c26733410d5fbb8a10ebf7a3c745e4d8 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 3 Oct 2018 14:51:09 +0000 Subject: [PATCH] [llvm-exegesis] Avoid yaml parser from calling sscanf for obvious non-matches (PR39102) deserializeMCOperand - ensure that we at least match the first character of the sscanf pattern before calling This reduces llvm-exegesis uops analysis of the instructions supported from btver2 from 5m13s to 2m1s on debug builds. llvm-svn: 343690 --- llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index a3dd56ca3a21..c61d869a2a67 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -90,9 +90,11 @@ private: assert(!String.empty()); int64_t IntValue = 0; double DoubleValue = 0; - if (sscanf(String.data(), kIntegerFormat, &IntValue) == 1) + if (String[0] == kIntegerFormat[0] && + sscanf(String.data(), kIntegerFormat, &IntValue) == 1) return llvm::MCOperand::createImm(IntValue); - if (sscanf(String.data(), kDoubleFormat, &DoubleValue) == 1) + if (String[0] == kDoubleFormat[0] && + sscanf(String.data(), kDoubleFormat, &DoubleValue) == 1) return llvm::MCOperand::createFPImm(DoubleValue); if (unsigned RegNo = getRegNo(String)) return llvm::MCOperand::createReg(RegNo);