https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79219

--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to H. Peter Anvin from comment #8)
> (In reply to Richard Biener from comment #1)
> > So you mean DW/W -> W, but that can result in the result being not
> > representable?
> > What's the desired behavior in this case?  Invoking undefined behavior?
> 
> When the output is not representable, the expected behavior is whatever the
> platform does when an ordinary division divides by zero (which usually means
> some variant of raise(SIGFPE) is invoked through one path or another.)

If this is the case, we already have appropriate pattern (although
commented-out ATM) in i386.md (the example is for 32-bit target, but can be
trivially changed to fit TImode/DImode on 64-bit targets)

--cut here--
;; We cannot use div/idiv for double division, because it causes
;; "division by zero" on the overflow and that's not what we expect
;; from truncate.  Because true (non truncating) double division is
;; never generated, we can't create this insn anyway.
;
;(define_insn ""
;  [(set (match_operand:SI 0 "register_operand" "=a")
;       (truncate:SI
;         (udiv:DI (match_operand:DI 1 "register_operand" "A")
;                  (zero_extend:DI
;                    (match_operand:SI 2 "nonimmediate_operand" "rm")))))
;   (set (match_operand:SI 3 "register_operand" "=d")
;       (truncate:SI
;         (umod:DI (match_dup 1) (zero_extend:DI (match_dup 2)))))
;   (clobber (reg:CC FLAGS_REG))]
;  ""
;  "div{l}\t{%2, %0|%0, %2}"
;  [(set_attr "type" "idiv")])
--cut here--

The comment suggests that middle-end has to be improved to detect and expand
TI/DI -> DI division in a similar generic way as DI/DI -> TI multiplication. 

OTOH, since the truncation of the result of the division doesn't trap, the
combined pattern also should not (combine pass can synthesize this pattern from
separate patterns). IMO, at least for x86, we need a builtin.

Reply via email to