-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed
Labels
floating-pointFloating-point mathFloating-point mathllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization
Description
These reassociatable fmuls by constants should preserve signed zero behavior, but do not fold unless nsz is attached to both multiplies
; RUN: opt -S -passes=instcombine %s
; Can't reassociate anyway
define float @fmul(float %x) {
%fmul0 = fmul float %x, 2.0
%fmul1 = fmul float %fmul0, 4.0
ret float %fmul1
}
; Should be able to reassociate without nsz
; (+0 * 2) * 4 = +0
; (-0 * 2) * 4 = -0
; (+0 * 8) = +0
; (-0 * 8) = -0
define float @fmul_reassoc(float %x) {
%fmul0 = fmul reassoc float %x, 2.0
%fmul1 = fmul reassoc float %fmul0, 4.0
ret float %fmul1
}
; (+0 * 2) * -4 = -0
; (-0 * 2) * -4 = +0
; (+0 * -8) = -0
; (-0 * -8) = +0
define float @fmul_reassoc_negative_0(float %x) {
%fmul0 = fmul reassoc float %x, 2.0
%fmul1 = fmul reassoc float %fmul0, -4.0
ret float %fmul1
}
; (+0 * -2) * 4 = -0
; (-0 * -2) * 4 = +0
; (+0 * -8) = -0
; (-0 * -8) = +0
define float @fmul_reassoc_negative_1(float %x) {
%fmul0 = fmul reassoc float %x, -2.0
%fmul1 = fmul reassoc float %fmul0, 4.0
ret float %fmul1
}
; Does reassociate already, unnecessarily requires nsz on both multiplies.
define float @fmul_reassoc_nsz(float %x) {
%fmul0 = fmul nsz reassoc float %x, 2.0
%fmul1 = fmul nsz reassoc float %fmul0, 4.0
ret float %fmul1
}
Metadata
Metadata
Assignees
Labels
floating-pointFloating-point mathFloating-point mathllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization