diff --git a/src/hotspot/share/opto/superword.cpp b/src/hotspot/share/opto/superword.cpp index 2316b0bb49a2c..7ee6b067810a2 100644 --- a/src/hotspot/share/opto/superword.cpp +++ b/src/hotspot/share/opto/superword.cpp @@ -2577,6 +2577,11 @@ static bool can_subword_truncate(Node* in, const Type* type) { return false; } + // Since casts specifically change the type of a node, stay on the safe side and do not truncate them. + if (in->is_ConstraintCast()) { + return false; + } + // Cannot be truncated: switch (opc) { case Op_AbsI: diff --git a/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java b/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java index 2256fd90e3507..af54e48a5a3a3 100644 --- a/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java +++ b/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java @@ -428,6 +428,32 @@ public Object[] testRoundD(byte[] in) { return new Object[] { in, res }; } + @Test(compLevel = CompLevel.C2) + @IR(counts = { IRNode.CAST_II, ">0" }) + @Warmup(0) + public Object[] testCastII() { + byte[] bytes = new byte[400]; + intField = 6; + int i = 0; + int j = 1; + + do { + bytes[j] = (byte) i; + int k = 1; + + do { + i <<= intField; + i += (k ^ i); + i -= j; + + for (int u = 1; 1 > u; u++) { + } + } while (++k < 8); + } while (++j < 191); + + return new Object[] { bytes }; + } + public static void main(String[] args) { TestFramework.run(); }