Closed HazyFish closed 9 months ago
cc @DataCorrupted
@llvm/issue-subscribers-backend-powerpc
It looks like BitPermutationSelector.getValueBits doesn't account for PPCISD shift opcodes handling of out of bounds shift amounts (or ISD::ROTL by the looks of it).
SelectionDAG has 34 nodes:
t0: ch,glue = EntryToken
t2: i64,ch = CopyFromReg t0, Register:i64 %0
t89: i64 = add t2, Constant:i64<24>
t16: i64 = add nuw t2, Constant:i64<16>
t30: i64,ch = load<(load (s64) from %ir.0 + 24, basealign 32)> t0, t89, undef:i64
t84: i64 = add t2, Constant:i64<12>
t83: i32,ch = load<(load (s32) from %ir.0 + 12)> t0, t84, undef:i64
t27: i64,ch = load<(load (s64) from %ir.0 + 16, align 16, basealign 32)> t0, t16, undef:i64
t80: i32 = add t83, Constant:i32<-12>
t92: i64 = PPCISD::SRL Constant:i64<12>, t80
t41: i64 = add t2, Constant:i64<8>
t60: ch = store<(store (s64) into %ir.0 + 8, basealign 32)> t83:1, t92, t41, undef:i64
t63: ch = store<(store (s64) into %ir.0, align 32)> t0, Constant:i64<0>, t2, undef:i64
t101: i64 = PPCISD::SRL t30, Constant:i32<0>
t102: i64 = PPCISD::SHL t27, Constant:i32<64>
t103: i64 = or t101, t102
t104: i64 = PPCISD::SRL t27, Constant:i32<-64>
t105: i64 = or t103, t104
t66: ch = store<(store (s64) into %ir.0 + 24, basealign 32)> t30:1, t105, t89, undef:i64
t106: i64 = PPCISD::SRL t27, Constant:i32<0>
t69: ch = store<(store (s64) into %ir.0 + 16, align 16, basealign 32)> t27:1, t106, t16, undef:i64
t73: ch = TokenFactor t60, t63, t66, t69
t12: ch = PPCISD::RET_FLAG t73
I posted https://reviews.llvm.org/D138551 for review.
Description
When targeting
ppc64
,ppc32
, orppc32le
, the following code containing i128 vector shift crashes backend due to index being out of bound duringPowerPC DAG->DAG Pattern Instruction Selection
.The problem occurs for
lshr
andshl
but not forashr
. The problem occurs forsub
but not foradd
and the result ofsub
must be used as the shift amount operand. The problem doesn't occur for i64 vectors. The problem doesn't occur when targetingppc64le
,aarch64
,x86_64
, orriscv64
.Minimal Reproduction
https://godbolt.org/z/vW4YT3Ga7
Code
Stack Trace
Cause
The following line returns the shift amount
4294967232
(-64
represented inunsigned
) which is wrong and caused out-of-bound access to vector in the following code.https://github.com/llvm/llvm-project/blob/af029d383a24ee454e1124f64f3427d5b79e5f7e/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp#L1502