8365570: C2 fails assert(false) failed: Unexpected node in SuperWord truncation: CastII

Reviewed-by: bmaillard, epeter
Backport-of: 775f48de6129092d05650fec17dad171944e6d89
This commit is contained in:
Tobias Hartmann 2026-01-09 10:38:55 +00:00
parent e0f1c3a746
commit 10d97c5e6e
2 changed files with 33 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2482,6 +2482,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:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -479,6 +479,32 @@ public class TestSubwordTruncation {
return new Object[] { in, res };
}
@Test
@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();
}