diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-04-02 09:38:08 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-04-02 09:38:08 -0700 |
commit | 99681c41b0bf46e9973cf4b3ef6d0b792103f29d (patch) | |
tree | f479307a68fa07023194eb9c0389cf8f5165db47 | |
parent | 26535c655b240324d5cdfcc61bec85d401f71214 (diff) |
Disable shift-compare instcombine optimization for NaCl.
This is one of at least 2 optimizations which introduce non-power-of-two
integer sizes, which we don't want to allow in the PNaCl stable wire format.
This transforms
(icmp pred iM (shl iM %value, N), ConstInt)
-> (icmp pred i(M-N) (trunc %value iM to i(N-N)), (trunc (ConstInt >> N))
and reduces the size of the compare and its operands.
R=mseaborn@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3360
Review URL: https://codereview.chromium.org/13182003
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 7 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/instcombine.ll | 24 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index bad46b4dab..0267117421 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1339,7 +1339,12 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, // free on the target. It has the additional benefit of comparing to a // smaller constant, which will be target friendly. unsigned Amt = ShAmt->getLimitedValue(TypeBits-1); - if (Amt != 0 && RHSV.countTrailingZeros() >= Amt) { + // @LOCALMOD-BEGIN + // We don't want to introduce non-power-of-two integer sizes for PNaCl's + // stable wire format, so modify this transformation for NaCl. + if (Amt != 0 && RHSV.countTrailingZeros() >= Amt && + isPowerOf2_32(TypeBits - Amt) && (TypeBits - Amt) >= 8) { + // @LOCALMOD-END Type *NTy = IntegerType::get(ICI.getContext(), TypeBits - Amt); Constant *NCI = ConstantExpr::getTrunc( ConstantExpr::getAShr(RHS, diff --git a/test/NaCl/PNaClABI/instcombine.ll b/test/NaCl/PNaClABI/instcombine.ll new file mode 100644 index 0000000000..e21eea45c4 --- /dev/null +++ b/test/NaCl/PNaClABI/instcombine.ll @@ -0,0 +1,24 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s +; Test that instcombine does not introduce non-power-of-two integers into +; the module + +target datalayout = "p:32:32:32" + +; This test is a counterpart to icmp_shl16 in +; test/Transforms/InstCombine/icmp.ll, which should still pass. +; CHECK: @icmp_shl31 +; CHECK-NOT: i31 +define i1 @icmp_shl31(i32 %x) { + %shl = shl i32 %x, 1 + %cmp = icmp slt i32 %shl, 36 + ret i1 %cmp +} + +; Check that we don't introduce i4, which is a power of 2 but still not allowed. +; CHECK: @icmp_shl4 +; CHECK-NOT: i4 +define i1 @icmp_shl4(i32 %x) { + %shl = shl i32 %x, 28 + %cmp = icmp slt i32 %shl, 1073741824 + ret i1 %cmp +} |