[llvm] [Reassociate] Drop weight reduction to fix issue 91417 (PR #91469)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 01:36:06 PDT 2024


dtcxzyw wrote:

> > > The original patch says:
> > > > This patch fixes the computation of weights by correctly computing them no matter how big they are, rather than just overflowing and getting a wrong value.
> > > 
> > > 
> > > Is "wrong" here in the sense that if overflow happens there may be a miscompile or "wrong" in the sense that the result may be sup-optimal?
> > 
> > 
> > See https://bugs.llvm.org/show_bug.cgi?id=13021. The original patch fixes the infinite loop. Reducing weights is just a "side-effect".
> 
> Will reverting this bring back the infinite loop?

At least it works well with the tests in repeats.ll and the original cases:
```
; opt -passes=reassociate test.ll -S
define float @patatino(float %x) {
  %t0 = fmul fast float %x, %x
  %t1 = fmul fast float %t0, %t0
  %t2 = fmul fast float %t1, %t1
  %t3 = fmul fast float %t2, %t2
  %t4 = fmul fast float %t3, %t3
  %t5 = fmul fast float %t4, %t4
  %t6 = fmul fast float %t5, %t5
  %t7 = fmul fast float %t6, %t6
  %t8 = fmul fast float %t7, %t7
  %t9 = fmul fast float %t8, %t8
  %t10 = fmul fast float %t9, %t9
  %t11 = fmul fast float %t10, %t10
  %t12 = fmul fast float %t11, %t11
  %t13 = fmul fast float %t12, %t12
  %t14 = fmul fast float %t13, %t13
  %t15 = fmul fast float %t14, %t14
  %t16 = fmul fast float %t15, %t15
  %t17 = fmul fast float %t16, %t16
  %t18 = fmul fast float %t17, %t17
  %t19 = fmul fast float %t18, %t18
  %t20 = fmul fast float %t19, %t19
  %t21 = fmul fast float %t20, %t20
  %t22 = fmul fast float %t21, %t21
  %t23 = fmul fast float %t22, %t22
  %t24 = fmul fast float %t23, %t23
  %t25 = fmul fast float %t24, %t24
  %t26 = fmul fast float %t25, %t25
  %t27 = fmul fast float %t26, %t26
  %t28 = fmul fast float %t27, %t27
  ret float %t28
}

define i8 @f2(i8 %a) {
  %2 = mul i8 %a, %a
  %3 = mul i8 %2, %2
  %4 = mul i8 %3, %3
  %5 = mul i8 %4, %4
  %6 = mul i8 %5, %5
  %7 = mul i8 %6, %6
  %8 = mul i8 %7, %7
  %9 = mul i8 %8, %8
  %10 = mul i8 %9, %9
  %11 = mul i8 %10, %10
  %12 = mul i8 %11, %11
  %13 = mul i8 %12, %12
  %14 = mul i8 %13, %13
  %15 = mul i8 %14, %14
  %16 = mul i8 %15, %15
  %17 = mul i8 %16, %16
  %18 = mul i8 %17, %17
  %19 = mul i8 %18, %18
  %20 = mul i8 %19, %19
  %21 = mul i8 %20, %20
  %22 = mul i8 %21, %21
  %23 = mul i8 %22, %22
  %24 = mul i8 %23, %23
  %25 = mul i8 %24, %24
  %26 = mul i8 %25, %25
  %27 = mul i8 %26, %26
  %28 = mul i8 %27, %27
  %29 = mul i8 %28, %28
  %30 = mul i8 %29, %29
  %31 = mul i8 %30, %30
  ret i8 %31
}
```


https://github.com/llvm/llvm-project/pull/91469


More information about the llvm-commits mailing list