From 957c22bed6a722ee8db2e564e7f48e4c9773ffe2 Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Mon, 30 Nov 2015 13:50:34 +0100 Subject: [PATCH] more profiling in vector access, avoid costly division if possible --- .../r/nodes/access/vector/CachedReplaceVectorNode.java | 9 ++++++--- .../r/nodes/access/vector/PositionCheckSubsetNode.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java index 323b2d034e..9bd54bbee5 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/CachedReplaceVectorNode.java @@ -59,6 +59,9 @@ final class CachedReplaceVectorNode extends CachedVectorNode { private final BranchProfile resizeProfile = BranchProfile.create(); private final BranchProfile sharedProfile = BranchProfile.create(); + private final ConditionProfile valueLengthOneProfile = ConditionProfile.createBinaryProfile(); + private final ConditionProfile emptyReplacementProfile = ConditionProfile.createBinaryProfile(); + private final RType valueType; private final RType castType; private final boolean updatePositionNames; @@ -190,12 +193,12 @@ final class CachedReplaceVectorNode extends CachedVectorNode { } int replacementLength = positionsCheckNode.getSelectedPositionsCount(positionProfiles); - if (replacementLength == 0) { + if (emptyReplacementProfile.profile(replacementLength == 0)) { /* Nothing to modify */ return vector; } - if (valueLength != 1) { + if (valueLengthOneProfile.profile(valueLength != 1)) { verifyValueLength(positionProfiles, valueLength); } @@ -227,7 +230,7 @@ final class CachedReplaceVectorNode extends CachedVectorNode { * Interestingly we always need to provide not NOT_MULTIPLE_REPLACEMENT error messages * for multi-dimensional deletes. */ - if ((this.numberOfDimensions > 1 && isNullValue()) || replacementLength % valueLength != 0) { + if ((this.numberOfDimensions > 1 && isNullValue()) || (replacementLength != valueLength && replacementLength % valueLength != 0)) { if (this.numberOfDimensions > 1) { errorBranch.enter(); throw RError.error(this, RError.Message.NOT_MULTIPLE_REPLACEMENT); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubsetNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubsetNode.java index a7943caf7d..9efd068bd0 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubsetNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubsetNode.java @@ -73,7 +73,7 @@ abstract class PositionCheckSubsetNode extends PositionCheckNode { } protected static boolean isMultiplesOf(int a, int b) { - return b != 0 && a % b == 0; + return b != 0 && (a == b || a % b == 0); } @Specialization(contains = "doLogicalMultiplesInBounds") -- GitLab