mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-13 14:47:00 +00:00
637f75559d
LegalizeIntegerTypes does not have a way to expand multiplications for large integer types (i.e. larger than twice the native bit width). There's no standard runtime call to use in that case, and so we'd just assert. Unfortunately, as it turns out, it is possible to hit this case from standard-ish C code in rare cases. A particular case a user ran into yesterday involved an __int128 induction variable and a loop with a quadratic (not linear) recurrence which triggered some backend logic using SCEVExpander. In this case, the BinomialCoefficient code in SCEV generates some i129 variables, which get widened to i256. At a high level, this is not actually good (i.e. the underlying optimization, PPCLoopPreIncPrep, should not be transforming the loop in question for performance reasons), but regardless, the backend shouldn't crash because of cost-modeling issues in the optimizer. This is a straightforward implementation of the multiplication expansion, based on the algorithm in Hacker's Delight. I validated it against the code for the mul256b function from http://locklessinc.com/articles/256bit_arithmetic/ using random inputs. There should be no functional change for previously-working code (the new expansion code only replaces an assert). Fixes PR19797. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270720 91177308-0d34-0410-b5e6-96231b3b80d8
28 lines
731 B
LLVM
28 lines
731 B
LLVM
; RUN: llc < %s | FileCheck %s
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
define void @test(i256* %a, i256* %b, i256* %out) #0 {
|
|
entry:
|
|
%av = load i256, i256* %a
|
|
%bv = load i256, i256* %b
|
|
%r = mul i256 %av, %bv
|
|
store i256 %r, i256* %out
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: @test
|
|
; There is a lot of inter-register motion, and so matching the instruction
|
|
; sequence will be fragile. There should be 6 underlying multiplications.
|
|
; CHECK: imulq
|
|
; CHECK: imulq
|
|
; CHECK: imulq
|
|
; CHECK: imulq
|
|
; CHECK: imulq
|
|
; CHECK: imulq
|
|
; CHECK-NOT: imulq
|
|
; CHECK: retq
|
|
|
|
attributes #0 = { norecurse nounwind uwtable "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" }
|
|
|