@@ -8640,7 +8640,8 @@ void GradientUtils::eraseFictiousPHIs() {
86408640 IRBuilder<> B (&*pp->getFunction ()->getEntryBlock ().getFirstInsertionPt ());
86418641
86428642 Value *sz = byteCount;
8643- if (sz->getType ()->isIntegerTy () && sz->getType ()->getIntegerBitWidth () != 64 )
8643+ if (sz->getType ()->isIntegerTy () &&
8644+ sz->getType ()->getIntegerBitWidth () != 64 )
86448645 sz = B.CreateZExtOrTrunc (sz, B.getInt64Ty (), " enzyme.sz64" );
86458646 else if (!sz->getType ()->isIntegerTy ())
86468647 sz = B.CreatePtrToInt (sz, B.getInt64Ty (), " enzyme.sz64" );
@@ -8666,7 +8667,8 @@ void GradientUtils::eraseFictiousPHIs() {
86668667 return rep;
86678668 };
86688669
8669- // Helper: handle malloc/calloc tagged !enzyme_fromstack by turning into alloca
8670+ // Helper: handle malloc/calloc tagged !enzyme_fromstack by turning into
8671+ // alloca
86708672 auto tryRematFromstackMalloc = [&](PHINode *pp, Value *orig) -> bool {
86718673 auto *CI = dyn_cast<CallInst>(orig);
86728674 if (!CI)
@@ -8692,10 +8694,13 @@ void GradientUtils::eraseFictiousPHIs() {
86928694 byteCount = getNewIfOriginal (const_cast <Value *>(CI->getArgOperand (0 )));
86938695 if (byteCount->getType ()->isIntegerTy () &&
86948696 byteCount->getType ()->getIntegerBitWidth () != 64 )
8695- byteCount = B.CreateZExtOrTrunc (byteCount, B.getInt64Ty (), " malloc.sz64" );
8697+ byteCount =
8698+ B.CreateZExtOrTrunc (byteCount, B.getInt64Ty (), " malloc.sz64" );
86968699 } else { // calloc(nmemb, size)
8697- Value *nmemb = getNewIfOriginal (const_cast <Value *>(CI->getArgOperand (0 )));
8698- Value *esize = getNewIfOriginal (const_cast <Value *>(CI->getArgOperand (1 )));
8700+ Value *nmemb =
8701+ getNewIfOriginal (const_cast <Value *>(CI->getArgOperand (0 )));
8702+ Value *esize =
8703+ getNewIfOriginal (const_cast <Value *>(CI->getArgOperand (1 )));
86998704 if (nmemb->getType ()->getIntegerBitWidth () != 64 )
87008705 nmemb = B.CreateZExtOrTrunc (nmemb, B.getInt64Ty (), " calloc.nmemb64" );
87018706 if (esize->getType ()->getIntegerBitWidth () != 64 )
@@ -8709,7 +8714,8 @@ void GradientUtils::eraseFictiousPHIs() {
87098714 if (name == " calloc" ) {
87108715 // rep might be a casted pointer; memset wants an i8*
87118716 Value *raw = rep;
8712- if (raw->getType () != PointerType::getUnqual (i8Ty) && raw->getType ()->isPointerTy ()) {
8717+ if (raw->getType () != PointerType::getUnqual (i8Ty) &&
8718+ raw->getType ()->isPointerTy ()) {
87138719 raw = B.CreateBitCast (raw, PointerType::getUnqual (i8Ty), " calloc.i8p" );
87148720 }
87158721 B.CreateMemSet (raw, B.getInt8 (0 ), byteCount, MaybeAlign (16 ));
@@ -8732,7 +8738,8 @@ void GradientUtils::eraseFictiousPHIs() {
87328738 isa<AtomicRMWInst>(I) || isa<AtomicCmpXchgInst>(I))
87338739 return false ;
87348740
8735- if (!I->mayReadFromMemory () && !I->mayWriteToMemory () && !I->mayHaveSideEffects ()) {
8741+ if (!I->mayReadFromMemory () && !I->mayWriteToMemory () &&
8742+ !I->mayHaveSideEffects ()) {
87368743 Instruction *cl = I->clone ();
87378744 cl->setName (I->getName () + " .remat" );
87388745
@@ -8796,7 +8803,8 @@ void GradientUtils::eraseFictiousPHIs() {
87968803 }
87978804 }
87988805
8799- // Last resort: replace with undef (keeps compilation going, but derivative may be wrong)
8806+ // Last resort: replace with undef (keeps compilation going, but derivative
8807+ // may be wrong)
88008808 if (!pp->use_empty ())
88018809 pp->replaceAllUsesWith (UndefValue::get (pp->getType ()));
88028810 erase (pp);
0 commit comments