llvm.org GIT mirror llvm / 8aaa99a
[WebAssembly] Handle errors better in fast-isel. Fast-isel routines need to bail out in the case that fast-isel fails on the operands. This fixes https://bugs.llvm.org/show_bug.cgi?id=35064 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319144 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 2 years ago
2 changed file(s) with 94 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
274274 }
275275 if (S == 1 && Addr.isRegBase() && Addr.getReg() == 0) {
276276 // An unscaled add of a register. Set it as the new base.
277 Addr.setReg(getRegForValue(Op));
277 unsigned Reg = getRegForValue(Op);
278 if (Reg == 0)
279 return false;
280 Addr.setReg(Reg);
278281 break;
279282 }
280283 if (canFoldAddIntoGEP(U, Op)) {
358361 if (Addr.isSet()) {
359362 return false;
360363 }
361 Addr.setReg(getRegForValue(Obj));
364 unsigned Reg = getRegForValue(Obj);
365 if (Reg == 0)
366 return false;
367 Addr.setReg(Reg);
362368 return Addr.getReg() != 0;
363369 }
364370
417423 }
418424
419425 Not = false;
420 return maskI1Value(getRegForValue(V), V);
426 unsigned Reg = getRegForValue(V);
427 if (Reg == 0)
428 return 0;
429 return maskI1Value(Reg, V);
421430 }
422431
423432 unsigned WebAssemblyFastISel::zeroExtendToI32(unsigned Reg, const Value *V,
534543 unsigned WebAssemblyFastISel::getRegForUnsignedValue(const Value *V) {
535544 MVT::SimpleValueType From = getSimpleType(V->getType());
536545 MVT::SimpleValueType To = getLegalType(From);
537 return zeroExtend(getRegForValue(V), V, From, To);
546 unsigned VReg = getRegForValue(V);
547 if (VReg == 0)
548 return 0;
549 return zeroExtend(VReg, V, From, To);
538550 }
539551
540552 unsigned WebAssemblyFastISel::getRegForSignedValue(const Value *V) {
541553 MVT::SimpleValueType From = getSimpleType(V->getType());
542554 MVT::SimpleValueType To = getLegalType(From);
543 return signExtend(getRegForValue(V), V, From, To);
555 unsigned VReg = getRegForValue(V);
556 if (VReg == 0)
557 return 0;
558 return signExtend(VReg, V, From, To);
544559 }
545560
546561 unsigned WebAssemblyFastISel::getRegForPromotedValue(const Value *V,
796811
797812 if (IsDirect)
798813 MIB.addGlobalAddress(Func);
799 else
800 MIB.addReg(getRegForValue(Call->getCalledValue()));
814 else {
815 unsigned Reg = getRegForValue(Call->getCalledValue());
816 if (Reg == 0)
817 return false;
818 MIB.addReg(Reg);
819 }
801820
802821 for (unsigned ArgReg : Args)
803822 MIB.addReg(ArgReg);
887906 const Value *Op = ZExt->getOperand(0);
888907 MVT::SimpleValueType From = getSimpleType(Op->getType());
889908 MVT::SimpleValueType To = getLegalType(getSimpleType(ZExt->getType()));
890 unsigned Reg = zeroExtend(getRegForValue(Op), Op, From, To);
909 unsigned In = getRegForValue(Op);
910 if (In == 0)
911 return false;
912 unsigned Reg = zeroExtend(In, Op, From, To);
891913 if (Reg == 0)
892914 return false;
893915
901923 const Value *Op = SExt->getOperand(0);
902924 MVT::SimpleValueType From = getSimpleType(Op->getType());
903925 MVT::SimpleValueType To = getLegalType(getSimpleType(SExt->getType()));
904 unsigned Reg = signExtend(getRegForValue(Op), Op, From, To);
926 unsigned In = getRegForValue(Op);
927 if (In == 0)
928 return false;
929 unsigned Reg = signExtend(In, Op, From, To);
905930 if (Reg == 0)
906931 return false;
907932
10431068 if (!VT.isSimple() || !RetVT.isSimple())
10441069 return false;
10451070
1071 unsigned In = getRegForValue(I->getOperand(0));
1072 if (In == 0)
1073 return false;
1074
10461075 if (VT == RetVT) {
10471076 // No-op bitcast.
1048 updateValueMap(I, getRegForValue(I->getOperand(0)));
1077 updateValueMap(I, In);
10491078 return true;
10501079 }
10511080
10521081 unsigned Reg = fastEmit_ISD_BITCAST_r(VT.getSimpleVT(), RetVT.getSimpleVT(),
1053 getRegForValue(I->getOperand(0)),
1054 I->getOperand(0)->hasOneUse());
1082 In, I->getOperand(0)->hasOneUse());
10551083 if (!Reg)
10561084 return false;
10571085 MachineBasicBlock::iterator Iter = FuncInfo.InsertPt;
3131 ret i32 0
3232 }
3333
34 ; CHECK: i32.const {{.*}}, addr@FUNCTION
35 ; CHECK: i32.const {{.*}}, 24
36 ; CHECK: i32.shl
37 ; CHECK: i32.const {{.*}}, 24
38 ; CHECK: i32.shr_s
39 ; CHECK: i32.const {{.*}}, 64
40 ; CHECK: br_if 0, $pop0
41 define hidden i32 @d() #0 {
42 entry:
43 %t = icmp slt i8 ptrtoint (void ()* @addr to i8), 64
44 br i1 %t, label %a, label %b
45 a:
46 unreachable
47 b:
48 ret i32 0
49 }
50
51 ; CHECK: i32.const {{.*}}, addr@FUNCTION
52 ; CHECK: i32.const {{.*}}, 255
53 ; CHECK: i32.and
54 ; CHECK: i32.const {{.*}}, 64
55 ; CHECK: br_if 0, $pop0
56 define hidden i32 @e() #0 {
57 entry:
58 %t = icmp ult i8 ptrtoint (void ()* @addr to i8), 64
59 br i1 %t, label %a, label %b
60 a:
61 unreachable
62 b:
63 ret i32 0
64 }
65
66 ; CHECK: i32.const {{.*}}, addr@FUNCTION
67 ; CHECK: i32.const {{.*}}, 24
68 ; CHECK: i32.shl
69 ; CHECK: i32.const {{.*}}, 24
70 ; CHECK: i32.shr_s
71 define hidden i32 @f() #0 {
72 entry:
73 %t = sext i8 ptrtoint (void ()* @addr to i8) to i32
74 ret i32 %t
75 }
76
77 ; CHECK: i32.const {{.*}}, addr@FUNCTION
78 ; CHECK: i32.const {{.*}}, 255
79 ; CHECK: i32.and
80 define hidden i32 @g() #0 {
81 entry:
82 %t = zext i8 ptrtoint (void ()* @addr to i8) to i32
83 ret i32 %t
84 }
85
86 declare void @addr()
87
3488 attributes #0 = { noinline optnone }