[llvm-commits] [llvm] r171136 - /llvm/trunk/lib/Target/X86/X86InstrArithmetic.td
Jakob Stoklund Olesen
stoklund at 2pi.dk
Thu Jan 3 09:13:38 PST 2013
On Jan 2, 2013, at 10:08 PM, Craig Topper <craig.topper at gmail.com> wrote:
> Does this apply to other targets too? The ARM divide instructions aren't marked as having side effects for instance.
It's complicated ;-)
AFAIK, on ARMv7-A division by zero doesn't trap, but simply returns 0 instead. On ARMv7-R, division by zero can be configured to raise an undefined instruction exception, but I don't know if any targets use that.
Floating point division by zero can also be configured to trap, but normally just sets a bit in the FPSCR.
/jakob
> On Wed, Jan 2, 2013 at 12:58 PM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>
> On Jan 2, 2013, at 11:44 AM, Craig Topper <craig.topper at gmail.com> wrote:
>
>> OK. Should we more explicitly set "hasSideEffects = 1" then so that its not subtly happening due to lack of a pattern?
>
> Yes, I think that is best. Ideally, all targets should work with guessInstructionProperties = 0. I would like to make that the default.
>
> You can add the test case to test/CodeGen/X86/early-ifcvt.ll
>
> Thanks,
> /jakob
>
>
>>
>> On Wed, Jan 2, 2013 at 11:11 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>>
>> On Jan 2, 2013, at 11:04 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>>
>> >
>> > On Dec 26, 2012, at 7:01 PM, Craig Topper <craig.topper at gmail.com> wrote:
>> >
>> >> Author: ctopper
>> >> Date: Wed Dec 26 21:01:18 2012
>> >> New Revision: 171136
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=171136&view=rev
>> >> Log:
>> >> Mark the divide instructions as hasSideEffects=0.
>> >
>> > Hi Craig,
>> >
>> > I don't think this is safe because div instructions can trap when the divisor is 0, and that means it is not safe to move them between basic blocks. See also llvm::isSafeToSpeculativelyExecute().
>>
>> For example:
>>
>> $ cat unsafe-div.c
>> int f(int a, int b) {
>> return b ? a/b : a;
>> }
>>
>> $ Release+Asserts/bin/clang -O -o- -S unsafe-div.c -mllvm -x86-early-ifcvt -mllvm -stress-early-ifcvt
>> .section __TEXT,__text,regular,pure_instructions
>> .globl _f
>> .align 4, 0x90
>> _f: ## @f
>> .cfi_startproc
>> ## BB#0: ## %entry
>> pushq %rbp
>> Ltmp2:
>> .cfi_def_cfa_offset 16
>> Ltmp3:
>> .cfi_offset %rbp, -16
>> movq %rsp, %rbp
>> Ltmp4:
>> .cfi_def_cfa_register %rbp
>> movl %edi, %eax
>> cltd
>> idivl %esi
>> testl %esi, %esi
>> cmovel %edi, %eax
>> popq %rbp
>> ret
>> .cfi_endproc
>>
>>
>> .subsections_via_symbols
>>
>>
>>
>>
>> --
>> ~Craig
>
>
>
>
> --
> ~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130103/24fc3f34/attachment.html>
More information about the llvm-commits
mailing list