From fcf0628d93d759ae36106f7a738f66cb77badc79 Mon Sep 17 00:00:00 2001 From: Preston Gurd Date: Wed, 3 Oct 2012 16:11:44 +0000 Subject: [PATCH] This Patch corrects a problem whereby the optimization to use a faster divide instruction (for Intel Atom) was not being done by Clang, because the type context used by Clang is not the default context. It fixes the problem by getting the global context types for each div/rem instruction in order to compare them against the types in the BypassTypeMap. Tests for this will be done as a separate patch to Clang. Patch by Tyler Nowicki. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165126 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/BypassSlowDivision.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Utils/BypassSlowDivision.cpp b/lib/Transforms/Utils/BypassSlowDivision.cpp index ac18b7d5a05..821b588112d 100644 --- a/lib/Transforms/Utils/BypassSlowDivision.cpp +++ b/lib/Transforms/Utils/BypassSlowDivision.cpp @@ -238,14 +238,24 @@ bool llvm::bypassSlowDivision(Function &F, if (!UseDivOp && !UseRemOp) continue; + // Skip division on vector types, only optimize integer instructions + if (!J->getType()->isIntegerTy()) + continue; + + // Get same type in global context + IntegerType *T = cast(J->getType()); + IntegerType *GT = IntegerType::get(getGlobalContext(), T->getBitWidth()); + // Continue if div/rem type is not bypassed - DenseMap::const_iterator BT = - BypassTypeMap.find(J->getType()); - if (BT == BypassTypeMap.end()) + DenseMap::const_iterator BI = BypassTypeMap.find(GT); + if (BI == BypassTypeMap.end()) continue; - IntegerType *BypassType = cast(BT->second); - MadeChange |= reuseOrInsertFastDiv(F, I, J, BypassType, UseDivOp, + // Get the bypass type in the original context + IntegerType *GBT = cast(BI->second); + IntegerType *BT = IntegerType::get(J->getContext(), GBT->getBitWidth()); + + MadeChange |= reuseOrInsertFastDiv(F, I, J, BT, UseDivOp, UseSignedOp, DivCache); } -- 2.34.1