
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.
192 lines
7.0 KiB
LLVM
192 lines
7.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
|
|
|
|
declare double @llvm.sqrt.f64(double)
|
|
|
|
define double @sqrt_div_fast(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_fast(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = fdiv fast double [[Z:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.sqrt.f64(double [[TMP0]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fmul fast double [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv fast double %y, %z
|
|
%sqrt = call fast double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv fast double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv double %y, %z
|
|
%sqrt = call double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_reassoc_arcp(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_reassoc_arcp(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = fdiv reassoc arcp double [[Z:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call reassoc arcp double @llvm.sqrt.f64(double [[TMP0]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fmul reassoc arcp double [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp reassoc double %y, %z
|
|
%sqrt = call arcp reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_reassoc_missing(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_reassoc_missing(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv arcp double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call reassoc arcp double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv reassoc arcp double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp double %y, %z
|
|
%sqrt = call arcp reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_reassoc_missing2(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_reassoc_missing2(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv reassoc arcp double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call arcp double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv reassoc arcp double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp reassoc double %y, %z
|
|
%sqrt = call arcp double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_reassoc_missing3(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_reassoc_missing3(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv reassoc arcp double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call reassoc arcp double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv arcp double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp reassoc double %y, %z
|
|
%sqrt = call arcp reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_arcp_missing(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_arcp_missing(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = fdiv reassoc double [[Z:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call reassoc arcp double @llvm.sqrt.f64(double [[TMP0]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fmul reassoc arcp double [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv reassoc double %y, %z
|
|
%sqrt = call arcp reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_arcp_missing2(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_arcp_missing2(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv reassoc arcp double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call reassoc double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv reassoc arcp double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp reassoc double %y, %z
|
|
%sqrt = call reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv arcp reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_arcp_missing3(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_arcp_missing3(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv reassoc arcp double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call reassoc arcp double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv reassoc double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv arcp reassoc double %y, %z
|
|
%sqrt = call arcp reassoc double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv reassoc double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
declare void @use(double)
|
|
define double @sqrt_div_fast_multiple_uses_1(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_fast_multiple_uses_1(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv fast double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: call void @use(double [[DIV]])
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv fast double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv fast double %y, %z
|
|
call void @use(double %div)
|
|
%sqrt = call fast double @llvm.sqrt.f64(double %div)
|
|
%div1 = fdiv fast double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define double @sqrt_div_fast_multiple_uses_2(double %x, double %y, double %z) {
|
|
; CHECK-LABEL: @sqrt_div_fast_multiple_uses_2(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv fast double [[Y:%.*]], [[Z:%.*]]
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[DIV]])
|
|
; CHECK-NEXT: call void @use(double [[SQRT]])
|
|
; CHECK-NEXT: [[DIV1:%.*]] = fdiv fast double [[X:%.*]], [[SQRT]]
|
|
; CHECK-NEXT: ret double [[DIV1]]
|
|
;
|
|
entry:
|
|
%div = fdiv fast double %y, %z
|
|
%sqrt = call fast double @llvm.sqrt.f64(double %div)
|
|
call void @use(double %sqrt)
|
|
%div1 = fdiv fast double %x, %sqrt
|
|
ret double %div1
|
|
}
|
|
|
|
define float @sqrt_non_div_operator(float %a) {
|
|
; CHECK-LABEL: @sqrt_non_div_operator(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[CONV:%.*]] = fpext float [[A:%.*]] to double
|
|
; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[CONV]])
|
|
; CHECK-NEXT: [[DIV:%.*]] = fdiv fast double [[CONV]], [[SQRT]]
|
|
; CHECK-NEXT: [[CONV2:%.*]] = fptrunc double [[DIV]] to float
|
|
; CHECK-NEXT: ret float [[CONV2]]
|
|
;
|
|
entry:
|
|
%conv = fpext float %a to double
|
|
%sqrt = call fast double @llvm.sqrt.f64(double %conv)
|
|
%div = fdiv fast double %conv, %sqrt
|
|
%conv2 = fptrunc double %div to float
|
|
ret float %conv2
|
|
}
|