File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -588,8 +588,31 @@ static SILValue constantFoldBinary(BuiltinInst *BI,
588
588
// Are there valid uses for these in stdlib?
589
589
case BuiltinValueKind::Add:
590
590
case BuiltinValueKind::Mul:
591
- case BuiltinValueKind::Sub:
592
- return nullptr ;
591
+ case BuiltinValueKind::Sub: {
592
+ OperandValueArrayRef Args = BI->getArguments ();
593
+ auto *LHS = dyn_cast<IntegerLiteralInst>(Args[0 ]);
594
+ auto *RHS = dyn_cast<IntegerLiteralInst>(Args[1 ]);
595
+ if (!RHS || !LHS)
596
+ return nullptr ;
597
+ APInt LHSI = LHS->getValue ();
598
+ APInt RHSI = RHS->getValue ();
599
+
600
+ switch (ID) {
601
+ default : llvm_unreachable (" Not all cases are covered!" );
602
+ case BuiltinValueKind::Add:
603
+ LHSI += RHSI;
604
+ break ;
605
+ case BuiltinValueKind::Mul:
606
+ LHSI *= RHSI;
607
+ break ;
608
+ case BuiltinValueKind::Sub:
609
+ LHSI -= RHSI;
610
+ break ;
611
+ }
612
+
613
+ SILBuilderWithScope B (BI);
614
+ return B.createIntegerLiteral (BI->getLoc (), BI->getType (), LHSI);
615
+ }
593
616
594
617
case BuiltinValueKind::And:
595
618
case BuiltinValueKind::AShr:
You can’t perform that action at this time.
0 commit comments