Skip to content

[MIPS64] Miscompilation at O1 in trunk #157521

@XChy

Description

@XChy

Testcase:

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "mips64el-unknown-linux-gnu"

@.str = constant [9 x i8] c"%016llx\0A\00"
@f = global [1 x i64] zeroinitializer

define i32 @func() {
entry:
  ret i32 0
}

define i32 @o() {
entry:
  callbr void asm sideeffect "", "!i,~{$1}"()
          to label %m [label %l]

m:                                                ; preds = %if.then, %entry
  %k.0 = phi i64 [ 3090282716504613, %entry ], [ 0, %if.then ]
  br label %ab

ab:                                               ; preds = %l, %if.then, %asm.fallthrough1, %m
  %k.1 = phi i64 [ %k.0, %m ], [ %k.3, %l ], [ 0, %if.then ], [ 0, %asm.fallthrough1 ]
  %j.1 = phi <8 x i32> [ zeroinitializer, %m ], [ %j.3, %l ], [ zeroinitializer, %if.then ], [ zeroinitializer, %asm.fallthrough1 ]
  %vecins = insertelement <8 x i32> %j.1, i32 0, i64 0
  callbr void asm sideeffect "", "!i,~{$1}"()
          to label %asm.fallthrough1 [label %l]

asm.fallthrough1:                                 ; preds = %ab
  %sext = shl i64 %k.1, 32
  %conv2 = ashr i64 %sext, 32
  store i64 %conv2, ptr @f, align 8
  callbr void asm sideeffect "", "!i,~{$1}"()
          to label %asm.fallthrough3 [label %ab]

asm.fallthrough3:                                 ; preds = %asm.fallthrough1
  %cmp = icmp eq ptr @func, inttoptr (i64 1 to ptr)
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %asm.fallthrough3
  callbr void asm sideeffect "", "!i,!i,!i,~{$1}"()
          to label %ad [label %ab, label %l, label %m]

ad:                                               ; preds = %if.then
  br label %l

l:                                                ; preds = %ad, %if.then, %ab, %entry
  %k.3 = phi i64 [ 0, %if.then ], [ 3090282716504613, %entry ], [ %k.1, %ab ], [ 0, %ad ]
  %j.3 = phi <8 x i32> [ zeroinitializer, %if.then ], [ zeroinitializer, %entry ], [ zeroinitializer, %ab ], [ %vecins, %ad ]
  callbr void asm sideeffect "", "!i,~{$1}"()
          to label %asm.fallthrough10 [label %ab]

asm.fallthrough10:                                ; preds = %l
  %vecext11 = extractelement <8 x i32> %j.3, i64 0
  %conv12 = zext i32 %vecext11 to i64
  store i64 %conv12, ptr @f, align 8
  br label %if.end

if.end:                                           ; preds = %asm.fallthrough10, %asm.fallthrough3
  ret i32 0
}

define i32 @main() {
entry:
  %call = call i32 @o()
  %0 = load i64, ptr @f, align 8
  %call1 = call i32 (ptr, ...) @printf(ptr @.str, i64 %0)
  ret i32 0
}

declare i32 @printf(ptr, ...)

Compile with O1 and run with qemu-mips64el:

000afa988392a225

Compile with O0/O2/O3 and run with qemu-mips64el:

ffffffff8392a225

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions