
The idea behind this canonicalization is that it allows us to handle less patterns, because we know that some will be canonicalized away. This is indeed very useful to e.g. know that constants are always on the right. However, this is only useful if the canonicalization is actually reliable. This is the case for constants, but not for arguments: Moving these to the right makes it look like the "more complex" expression is guaranteed to be on the left, but this is not actually the case in practice. It fails as soon as you replace the argument with another instruction. The end result is that it looks like things correctly work in tests, while they actually don't. We use the "thwart complexity-based canonicalization" trick to handle this in tests, but it's often a challenge for new contributors to get this right, and based on the regressions this PR originally exposed, we clearly don't get this right in many cases. For this reason, I think that it's better to remove this complexity canonicalization. It will make it much easier to write tests for commuted cases and make sure that they are handled.
71 lines
2.9 KiB
LLVM
71 lines
2.9 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
|
|
; RUN: opt < %s -passes=reassociate,instcombine -S | FileCheck %s
|
|
|
|
; Not marked as fast, so must not change.
|
|
define float @test1(float %a0, float %a1, float %a2, float %a3, float %a4) {
|
|
; CHECK-LABEL: define float @test1(
|
|
; CHECK-SAME: float [[A0:%.*]], float [[A1:%.*]], float [[A2:%.*]], float [[A3:%.*]], float [[A4:%.*]]) {
|
|
; CHECK-NEXT: [[TMP_2:%.*]] = fadd float [[A3]], [[A4]]
|
|
; CHECK-NEXT: [[TMP_4:%.*]] = fadd float [[A2]], [[TMP_2]]
|
|
; CHECK-NEXT: [[TMP_6:%.*]] = fadd float [[A1]], [[TMP_4]]
|
|
; CHECK-NEXT: [[TMP_8:%.*]] = fadd float [[A0]], [[TMP_6]]
|
|
; CHECK-NEXT: [[TMP_11:%.*]] = fadd float [[A2]], [[A3]]
|
|
; CHECK-NEXT: [[TMP_13:%.*]] = fadd float [[A1]], [[TMP_11]]
|
|
; CHECK-NEXT: [[TMP_15:%.*]] = fadd float [[A0]], [[TMP_13]]
|
|
; CHECK-NEXT: [[TMP_18:%.*]] = fadd float [[A1]], [[A2]]
|
|
; CHECK-NEXT: [[TMP_20:%.*]] = fadd float [[A0]], [[TMP_18]]
|
|
; CHECK-NEXT: [[TMP_23:%.*]] = fadd float [[A0]], [[A1]]
|
|
; CHECK-NEXT: [[TMP_26:%.*]] = fsub float [[TMP_8]], [[TMP_15]]
|
|
; CHECK-NEXT: [[TMP_28:%.*]] = fadd float [[TMP_20]], [[TMP_26]]
|
|
; CHECK-NEXT: [[TMP_30:%.*]] = fsub float [[TMP_28]], [[TMP_23]]
|
|
; CHECK-NEXT: [[TMP_32:%.*]] = fsub float [[TMP_30]], [[A4]]
|
|
; CHECK-NEXT: [[TMP_34:%.*]] = fsub float [[TMP_32]], [[A2]]
|
|
; CHECK-NEXT: [[T:%.*]] = fmul float [[TMP_34]], [[TMP_34]]
|
|
; CHECK-NEXT: ret float [[T]]
|
|
;
|
|
|
|
%tmp.2 = fadd float %a4, %a3
|
|
%tmp.4 = fadd float %tmp.2, %a2
|
|
%tmp.6 = fadd float %tmp.4, %a1
|
|
%tmp.8 = fadd float %tmp.6, %a0
|
|
%tmp.11 = fadd float %a3, %a2
|
|
%tmp.13 = fadd float %tmp.11, %a1
|
|
%tmp.15 = fadd float %tmp.13, %a0
|
|
%tmp.18 = fadd float %a2, %a1
|
|
%tmp.20 = fadd float %tmp.18, %a0
|
|
%tmp.23 = fadd float %a1, %a0
|
|
%tmp.26 = fsub float %tmp.8, %tmp.15
|
|
%tmp.28 = fadd float %tmp.26, %tmp.20
|
|
%tmp.30 = fsub float %tmp.28, %tmp.23
|
|
%tmp.32 = fsub float %tmp.30, %a4
|
|
%tmp.34 = fsub float %tmp.32, %a2
|
|
%T = fmul float %tmp.34, %tmp.34
|
|
ret float %T
|
|
}
|
|
|
|
; Should be able to eliminate everything.
|
|
define float @test2(float %a0, float %a1, float %a2, float %a3, float %a4) {
|
|
; CHECK-LABEL: define float @test2(
|
|
; CHECK-SAME: float [[A0:%.*]], float [[A1:%.*]], float [[A2:%.*]], float [[A3:%.*]], float [[A4:%.*]]) {
|
|
; CHECK-NEXT: ret float 0.000000e+00
|
|
;
|
|
|
|
%tmp.2 = fadd fast float %a4, %a3
|
|
%tmp.4 = fadd fast float %tmp.2, %a2
|
|
%tmp.6 = fadd fast float %tmp.4, %a1
|
|
%tmp.8 = fadd fast float %tmp.6, %a0
|
|
%tmp.11 = fadd fast float %a3, %a2
|
|
%tmp.13 = fadd fast float %tmp.11, %a1
|
|
%tmp.15 = fadd fast float %tmp.13, %a0
|
|
%tmp.18 = fadd fast float %a2, %a1
|
|
%tmp.20 = fadd fast float %tmp.18, %a0
|
|
%tmp.23 = fadd fast float %a1, %a0
|
|
%tmp.26 = fsub fast float %tmp.8, %tmp.15
|
|
%tmp.28 = fadd fast float %tmp.26, %tmp.20
|
|
%tmp.30 = fsub fast float %tmp.28, %tmp.23
|
|
%tmp.32 = fsub fast float %tmp.30, %a4
|
|
%tmp.34 = fsub fast float %tmp.32, %a2
|
|
%T = fmul fast float %tmp.34, %tmp.34
|
|
ret float %T
|
|
}
|