Skip to content

condition jump instruction seems lost when optimization opened with -O1 or -O2 or -Oz #82744

Open
@haifengdeng

Description

@haifengdeng

when i use below command to compile FFmpeg 4.3.1 libavformat/utils.c with Clang 14 on Macmini M1 macOS 14.3.1:

/opt/homebrew/opt/llvm@14/bin/clang -I. -I./ --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk -D_ISOC99_SOURCE -D_LARGEFILE_SOURCE -I./compat/dispatch_semaphore -DPIC -DZLIB_CONST -DHAVE_AV_CONFIG_H -DBUILDING_avformat -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk -arch arm64 -mios-version-min=11.0 -no-canonical-prefixes -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -funwind-tables -fstack-protector-strong -fno-addrsig -Werror=return-type -Werror=int-to-pointer-cast -Werror=implicit-function-declaration -fPIC -DTARGET_OS_IPHONE=1 -Wall -pipe -std=c99 -ffast-math -g -O0 -DDEBUG_ENABLE -I/Users/yue/gitlab/libaveditor_6/buildbin_ios/tmp/arm64/include -std=c11 -Werror=partial-availability -fomit-frame-pointer -fPIC -pthread  -DX264_API_IMPORTS -I/opt/homebrew/Cellar/x264/r3108/include -ggdb -Wdeclaration-after-statement -Wall -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -Wno-unused-const-variable -Wno-bool-operation -Wno-char-subscripts -Oz -fno-math-errno -fno-signed-zeros -mstack-alignment=16 -Qunused-arguments -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type  -MMD -MF libavformat/utils.d -MT libavformat/utils.o -c -o libavformat/utils.o libavformat/utils.c

then I disassembe like below:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump -S libavformat/utils.o > utils14.txt

I found code if (st->index_entries) { in function ff_seek_frame_binary compiled like below, when I run to here, it always crashes:

;     av_log(s, AV_LOG_TRACE, "read_seek: %d %s\n", stream_index, av_ts2str(target_ts));
    2b00: 4f00e400     	movi.16b	v0, #0
    2b04: ad0403e0     	stp	q0, q0, [sp, #128]
    2b08: 910203f4     	add	x20, sp, #128
    2b0c: 910203e0     	add	x0, sp, #128
    2b10: aa0203e1     	mov	x1, x2
    2b14: 94000000     	bl	0x2b14 <_ff_seek_frame_binary+0x5c>
    2b18: a90053f7     	stp	x23, x20, [sp]
    2b1c: 90000002     	adrp	x2, 0x2000 <_ff_seek_frame_binary+0x64>
    2b20: 91000042     	add	x2, x2, #0
    2b24: 94000000     	bl	0x2b24 <_ff_seek_frame_binary+0x6c>
;     st = s->streams[stream_index];
    2b28: f9401a68     	ldr	x8, [x19, #48]
    2b2c: f8775914     	ldr	x20, [x8, w23, uxtw  #3]
**;     if (st->index_entries) {
    2b30: f940e69a     	ldr	x26, [x20, #456]**
;                                           flags | AVSEEK_FLAG_BACKWARD);
    2b34: 320002c2     	orr	w2, w22, #0x1
    2b38: 94000000     	bl	0x2b38 <_ff_seek_frame_binary+0x80>
;         index = FFMAX(index, 0);
    2b3c: 0aa07c08     	bic	w8, w0, w0, asr #31
;         if (e->timestamp <= target_ts || e->pos == e->min_distance) {
    2b40: 52800309     	mov	w9, #24
    2b44: 9ba96909     	umaddl	x9, w8, w9, x26
    2b48: a9406139     	ldp	x25, x24, [x9]
    2b4c: eb15031f     	cmp	x24, x21
    2b50: 540000cd     	b.le	0x2b68 <_ff_seek_frame_binary+0xb0>
    2b54: 52800309     	mov	w9, #24
;         if (e->timestamp <= target_ts || e->pos == e->min_distance) {

but when I use Clang 13 with same the compile command, it generates the code below:

;     av_log(s, AV_LOG_TRACE, "read_seek: %d %s\n", stream_index, av_ts2str(target_ts));
    2b14: 4f00e400     	movi.16b	v0, #0
    2b18: ad0383e0     	stp	q0, q0, [sp, #112]
    2b1c: 9101c3f4     	add	x20, sp, #112
    2b20: 9101c3e0     	add	x0, sp, #112
    2b24: aa0203e1     	mov	x1, x2
    2b28: 94000000     	bl	0x2b28 <_ff_seek_frame_binary+0x58>
    2b2c: a90053f7     	stp	x23, x20, [sp]
    2b30: 90000002     	adrp	x2, 0x2000 <_ff_seek_frame_binary+0x60>
    2b34: 91000042     	add	x2, x2, #0
    2b38: 94000000     	bl	0x2b38 <_ff_seek_frame_binary+0x68>
;     st = s->streams[stream_index];
    2b3c: f9401a68     	ldr	x8, [x19, #48]
    2b40: f8775914     	ldr	x20, [x8, w23, uxtw  #3]
**;     if (st->index_entries) {
    2b44: f940e69a     	ldr	x26, [x20, #456]
    2b48: b400033a     	cbz	x26, 0x2bac <_ff_seek_frame_binary+0xdc>**
;                                           flags | AVSEEK_FLAG_BACKWARD);
    2b4c: 320002c2     	orr	w2, w22, #0x1
    2b50: 94000000     	bl	0x2b50 <_ff_seek_frame_binary+0x80>
;         index = FFMAX(index, 0);
    2b54: 0aa07c08     	bic	w8, w0, w0, asr #31
;         if (e->timestamp <= target_ts || e->pos == e->min_distance) {

someone can help me find if my compile command has an error somewhere?

utils.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions