New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 40325 - [Mips] FastISel fails to mask branch conditions
Summary: [Mips] FastISel fails to mask branch conditions
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: MIPS (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-15 13:41 PST by Nikita Popov
Modified: 2019-02-25 10:55 PST (History)
1 user (show)

See Also:
Fixed By Commit(s): 354808


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Popov 2019-01-15 13:41:54 PST
Originally reported at: https://github.com/rust-lang/rust/issues/57631

Test case:

define void @test(i32 %x, i1* %p) {
  %y = and i32 %x, 1
  %c = icmp eq i32 %y, 1
  store i1 %c, i1* %p
  br i1 %c, label %foo, label %foo

foo:
  ret void
}

Running this through llc -march=mipsel -mcpu=mips32 -relocation-model=pic -O0 gives:

# %bb.0:
	move	$1, $4
	andi	$4, $4, 1
	sb	$4, 0($5)
	bgtz	$1, $BB0_1
	nop
# %bb.1:                                # %foo
	jr	$ra
	nop

While the sb is correct, the bgtz argument is the unmasked function argument.

The cause is very similar to https://bugs.llvm.org/show_bug.cgi?id=40172. In https://github.com/llvm-mirror/llvm/blob/00f59269287658489eda6279e52ae058dc686c96/lib/Target/Mips/MipsFastISel.cpp#L955 an icmp result stored in an i32 virtual register is assumed to have only value 0 or 1, while in reality only the low-bit of the register has a well-defined value.

In https://github.com/llvm-mirror/llvm/commit/7b129940425f14653692ae13dc7a33d551413444 a variant of this issue affecting i1 icmps was fixed. However, the issue is more general than that and can occur with arbitrary icmps if they come from a SelectionDAG fallback and happen to be combined in just the right way.

I believe the correct way to handle this is to fastEmitZExtFromI1() the branch condition (even though this will regress FastISel code quality).
Comment 1 Nikita Popov 2019-02-23 04:13:17 PST
https://reviews.llvm.org/D58576
Comment 2 Nikita Popov 2019-02-25 10:55:19 PST
Fixed by https://reviews.llvm.org/rL354808.